@@ -25,8 +25,7 @@ class TUSExecutor: NSObject, URLSessionDelegate {
2525// request.addValue(contentLength, forHTTPHeaderField: "Content-Length")
2626// request.addValue(uploadLength, forHTTPHeaderField: "Upload-Length")
2727 request. addValue ( TUSConstants . TUSProtocolVersion, forHTTPHeaderField: " TUS-Resumable " )
28- request. addValue ( String ( format: " %@ %@ " , " filename " , fileName. toBase64 ( ) ) , forHTTPHeaderField: " Upload-Metadata " )
29-
28+
3029 for header in headers. merging ( customHeaders, uniquingKeysWith: { ( current, _) in current } ) {
3130 request. addValue ( header. value, forHTTPHeaderField: header. key)
3231 }
@@ -35,13 +34,13 @@ class TUSExecutor: NSObject, URLSessionDelegate {
3534 }
3635
3736 internal func create( forUpload upload: TUSUpload ) {
38- var request : URLRequest = urlRequest ( withEndpoint: " " , andMethod: " POST " , andContentLength: upload. contentLength!, andUploadLength: upload. uploadLength!, andFilename: upload. id! , andHeaders: [ " Upload-Extension " : " creation " ] )
37+ var request : URLRequest = urlRequest ( withEndpoint: " " , andMethod: " POST " , andContentLength: upload. contentLength!, andUploadLength: upload. uploadLength!, andFilename: upload. id, andHeaders: [ " Upload-Extension " : " creation " , " Upload-Metadata " : upload . encodedMetadata ] )
3938 request. addValue ( upload. contentLength!, forHTTPHeaderField: " Content-Length " )
4039 request. addValue ( upload. uploadLength!, forHTTPHeaderField: " Upload-Length " )
4140 let task = TUSClient . shared. tusSession. session. dataTask ( with: request) { ( data, response, error) in
4241 if let httpResponse = response as? HTTPURLResponse {
4342 if httpResponse. statusCode == 201 {
44- TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " File %@ created " , upload. id! ) )
43+ TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " File %@ created " , upload. id) )
4544 // Set the new status and other props for the upload
4645 upload. status = . created
4746// upload.contentLength = httpResponse.allHeaderFields["Content-Length"] as? String
@@ -62,9 +61,9 @@ class TUSExecutor: NSObject, URLSessionDelegate {
6261 */
6362 //First we create chunks
6463 //MARK: FIX THIS
65- TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " Preparing upload data for file %@ " , upload. id! ) )
66- let uploadData = try ! Data ( contentsOf: URL ( fileURLWithPath: String ( format: " %@%@%@ " , TUSClient . shared. fileManager. fileStorePath ( ) , upload. id! , upload. fileType!) ) )
67- let fileName = String ( format: " %@%@ " , upload. id! , upload. fileType!)
64+ TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " Preparing upload data for file %@ " , upload. id) )
65+ let uploadData = try ! Data ( contentsOf: URL ( fileURLWithPath: String ( format: " %@%@%@ " , TUSClient . shared. fileManager. fileStorePath ( ) , upload. id, upload. fileType!) ) )
66+ let fileName = String ( format: " %@%@ " , upload. id, upload. fileType!)
6867 let tusName = String ( format: " TUS-%@ " , fileName)
6968 //let uploadData = try! UserDefaults.standard.data(forKey: tusName)
7069 //upload.data = uploadData
@@ -77,8 +76,8 @@ class TUSExecutor: NSObject, URLSessionDelegate {
7776 }
7877
7978 private func upload( forChunks chunks: [ Data ] , withUpload upload: TUSUpload , atPosition position: Int ) {
80- TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " Upload starting for file %@ - Chunk %u / %u " , upload. id! , position + 1 , chunks. count) )
81- let request : URLRequest = urlRequest ( withFullURL: upload. uploadLocationURL!, andMethod: " PATCH " , andContentLength: upload. contentLength!, andUploadLength: upload. uploadLength!, andFilename: upload. id! , andHeaders: [ " Content-Type " : " application/offset+octet-stream " , " Upload-Offset " : upload. uploadOffset!, " Content-Length " : String ( chunks [ position] . count) ] )
79+ TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " Upload starting for file %@ - Chunk %u / %u " , upload. id, position + 1 , chunks. count) )
80+ let request : URLRequest = urlRequest ( withFullURL: upload. uploadLocationURL!, andMethod: " PATCH " , andContentLength: upload. contentLength!, andUploadLength: upload. uploadLength!, andFilename: upload. id, andHeaders: [ " Content-Type " : " application/offset+octet-stream " , " Upload-Offset " : upload. uploadOffset!, " Content-Length " : String ( chunks [ position] . count) , " Upload-Metadata " : upload . encodedMetadata ] )
8281 let task = TUSClient . shared. tusSession. session. uploadTask ( with: request, from: chunks [ position] , completionHandler: { ( data, response, error) in
8382 if let httpResponse = response as? HTTPURLResponse {
8483 switch httpResponse. statusCode {
@@ -93,7 +92,7 @@ class TUSExecutor: NSObject, URLSessionDelegate {
9392 if ( httpResponse. statusCode == 204 ) {
9493 TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " Chunk %u / %u complete " , position + 1 , chunks. count) )
9594 if ( position + 1 == chunks. count) {
96- TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " File %@ uploaded at %@ " , upload. id! , upload. uploadLocationURL!. absoluteString) )
95+ TUSClient . shared. logger. log ( forLevel: . Info, withMessage: String ( format: " File %@ uploaded at %@ " , upload. id, upload. uploadLocationURL!. absoluteString) )
9796 TUSClient . shared. updateUpload ( upload)
9897 TUSClient . shared. delegate? . TUSSuccess ( forUpload: upload)
9998 TUSClient . shared. cleanUp ( forUpload: upload)
0 commit comments