Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix URLSessionImplementations file upload
  • Loading branch information
jerbob92 committed Apr 6, 2020
commit 7f3e68bc9c1eba631499ae09ab8140fdffdb2e81
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ fileprivate class FileUploadEncoding: ParameterEncoding {
}

var body = urlRequest.httpBody.orEmpty
body.append("--\(boundary)--")

body.append("\r\n--\(boundary)--\r\n")

urlRequest.httpBody = body

Expand All @@ -507,15 +507,24 @@ fileprivate class FileUploadEncoding: ParameterEncoding {
let mimetype = self.contentTypeForFormPart(fileURL) ?? mimeType(for: fileURL)

let fileName = fileURL.lastPathComponent


// If we already added something then we need an additional newline.
if (body.count > 0) {
body.append("\r\n")
}

// Value boundary.
body.append("--\(boundary)\r\n")
body.append("Content-Disposition: form-data; name=\"\(name)\"; filename=\"\(fileName)\"\r\n\r\n")

body.append("Content-Type: \(mimetype)\r\n\r\n")
// Value headers.
body.append("Content-Disposition: form-data; name=\"\(name)\"; filename=\"\(fileName)\"\r\n")
body.append("Content-Type: \(mimetype)\r\n")

body.append(fileData)
// Separate headers and body.
body.append("\r\n")

body.append("\r\n\r\n")
// The value data.
body.append(fileData)

urlRequest.httpBody = body

Expand All @@ -527,14 +536,24 @@ fileprivate class FileUploadEncoding: ParameterEncoding {
var urlRequest = urlRequest

var body = urlRequest.httpBody.orEmpty


// If we already added something then we need an additional newline.
if (body.count > 0) {
body.append("\r\n")
}

// Value boundary.
body.append("--\(boundary)\r\n")
body.append("Content-Disposition: form-data; name=\"\(name)\"\r\n\r\n")

// Value headers.
body.append("Content-Disposition: form-data; name=\"\(name)\"\r\n")

// Separate headers and body.
body.append("\r\n")

// The value data.
body.append(data)

body.append("\r\n\r\n")


urlRequest.httpBody = body

return urlRequest
Expand Down