Skip to content

Commit

Permalink
Fix: Remove extra boundary when appending files data for uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jerilyngigigo committed Feb 21, 2020
1 parent 37bf5d0 commit 7c7e3c8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Source/SwiftNetwork/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ open class Request: Selfie {
}

fileprivate func buildUploadData(files: [FileUploadData], params: [String: Any], boundary: String) -> Data {

var data = Data()
guard let boundaryData = "\r\n--\(boundary)\r\n".data(using: .utf8) else { return data }

print("- BODY:\n") // !!!
for (key, value) in params {
guard
let boundaryData = "\r\n--\(boundary)\r\n".data(using: .utf8),
let keyData = "Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n".data(using: .utf8),
let valueData = "\(value)".data(using: .utf8) else {
return data
Expand All @@ -434,7 +434,6 @@ open class Request: Selfie {

for file in files {
guard
let boundaryData = "\r\n--\(boundary)\r\n".data(using: .utf8),
let contentDispositionData = "Content-Disposition: form-data; name=\"\(file.name)\"; filename=\"\(file.filename)\"\r\n".data(using: .utf8),
let contentTypeData = "Content-Type: \(file.mimeType)\r\n\r\n".data(using: .utf8) else {
return data
Expand All @@ -447,10 +446,9 @@ open class Request: Selfie {
data.append(contentTypeData)
print(file.data)
data.append(file.data)
print("\\r\\n--\(boundary)\\r\\n")
data.append(boundaryData)
}

print("\\r\\n--\(boundary)\\r\\n")
data.append(boundaryData)
return data
}
}
Expand Down

0 comments on commit 7c7e3c8

Please sign in to comment.