The request that I get on the server side is missing content-lengtheach multipart.
I tried changing the headers, but it still won’t display.
I successfully send the image file and some data from the device / simulator to the server using Alamofire / multipart form-data strong>.
var parameters = […]
let url = try! URLRequest(url: "URL", method: .post, headers: ["Content-type": "multipart/form-data"])
Alamofire.upload(multipartFormData: { (multipartFormData) in
for (key, value) in parameters {
multipartFormData.append((value.data(using: String.Encoding.utf8)!), withName:key)
}
multipartFormData.append(UIImageJPEGRepresentation(image!, 0.5)!, withName: "Image", mimeType: "image/jpeg")
}, to: "\(url)" , encodingCompletion: {(encodingResult) in
switch encodingResult {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (Progress) in
self.progressView.progress = Float(Progress.fractionCompleted)
print("Upload Progress: \(Progress.fractionCompleted)")
})
print("REQUEST = \(request)")
print(encodingResult)
upload.responseJSON { response in
print( response.request)
print(response.response)
print(response.data)
print(response.result)
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
case .failure(let encodingError):
print(encodingError)
}
})
Update: Even after saving, headers: nilit will not be displayed.
Retrieved from alamofire: -
--alamofire.boundary.cc9684e085522290
Content-Disposition: form-data; xyz="abc"
123456
--alamofire.boundary.cc9684e085522290
How to get the length of the content for each transmitted data set?
user9039131
source
share