Я делаю ниже, чтобы загрузить PNG файл с параметрами:
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")
// Send parameters
multipartFormData.append((UserDefaults.standard.value(forKey: Email) as! String).data(using: .utf8)!, withName: "email")
multipartFormData.append("png".data(using: .utf8)!, withName: "type")
},
to: "user/picture",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint("SUCCESS RESPONSE: \(response)")
}
case .failure(let encodingError):
self.removeSpinnerFromView()
print("ERROR RESPONSE: \(encodingError)")
}
}
)
Проблема в том, что на моем сервере я не вижу поля формы email
и type
. Я следил за примерами, опубликованными в Интернете для этого. Есть ли что-то, что я должен сделать по-другому для этого?
ИЗМЕНИТЬ
Если я удалю часть, в которую я положил:
multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")
THEN параметры включены. В противном случае, я думаю, что это ошибка в Alamofire 4.0.1.