Hello,
I'm trying to update my project with the 4.0 version.
But got one issue with the upload. Even if I copy/past the upload multipart form form the README, I got this error :

With the old version I used this for upload image to my backend service :
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(data: imgData, name: "file", fileName: "image", mimeType: "image/jpeg")
},
to: url, encodingCompletion: { (encodingResult) in
//
})
Have you any solution to do it with Alamofire 4.0 ?
Thank you
I'm also getting this issue as well as many other "ambiguous without more context" errors. My feeling is that the fact that Alamofire doesn't use named first parameters but overloads them with multiple types AND the fact that many functions have default values is confusing the Swift 3 parser.
The documentation/readme at this point is very unreliable. It must match the method definitions exactly as provided by the library, so I would refer to the source code of the request/upload functions instead of the readme.
I got mine to work by letting XCode autocomplete what parameters I would need and fill those in.
In your specific example, don't state the data: part and name is renamed to withName. So multipartFormData.append(imgData, withName: "file", fileName: "image", mimeType: "image/jpeg")
The README has been fully updated for Alamofire 4 and all of our code examples build just fine, so it's not a reliability issue. Please take a look at the Migration Guide for some of the renames the framework has gone through. Otherwise, yes, you'll need to read the header documentation, or if browser reading is better for you, the documentation at CocoaDocs is up-to-date with our latest header docs.
I had the same issue guys, here's how I solved it! Go down to the accepted answer
http://stackoverflow.com/questions/39592085/swift-3-alamofire-multipart-upload/39593545
Hey i am using Alamofire 4.0 image uploading is done successfully with the following code but i am unable to send parameters with image. Please help me.
let imageData = UIImagePNGRepresentation(self.signatureImgView.image!)
let defaultHTTPHeaders: HTTPHeaders = [
"token": "F3pObDt2G832hfAaBhZDHekNHUhT62URXPApKkfPQBb9enSy",
"Accept": "application/json",
]
let URL2 = try! URLRequest(url: "http://52.66..........", method: .post, headers: defaultHTTPHeaders)
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(imageData!, withName: "signImg", fileName: "picture.png", mimeType: "image/png")
// for (key, value) in self.parameters {
// multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
// }
}, with: URL2, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON
{
response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value
{
print("JSON: (JSON)")
}
}
case .failure(let encodingError):
print(encodingError)
}
})
}
i have tried this
let parameters: [String: AnyObject] =
[
"email":"[email protected]" as AnyObject
]
for (key, value) in parameters
{
multipartFormData.append(value.data(using: "email".Encoding.utf8)!, withName: "[email protected]")
}
but it's not working!!! Please help me.
`func upload(_ url:String, parameters: [String:Data], callback:@escaping (Bool, JSON?,JSON?) -> Void){
let URL2 = try! URLRequest(url: mainUrl+"user/upload_profile", method: .post, headers: head)
Alamofire.upload(multipartFormData: { (multipartFormData) in
for (key, value) in parameters {
multipartFormData.append(value, withName: key, fileName: "picture.png", mimeType: "image/png")
}
}, with: URL2, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON{
response in
if let data = response.result.value{
DispatchQueue.main.async {
if(response.response?.statusCode == 200){
callback(true, JSON(data), JSON((response.response?.statusCode)!))
} else{
callback(false, JSON(data), JSON((response.response?.statusCode)!))
}
}
}
}
case .failure(let encodingError):
print(encodingError)
DispatchQueue.main.async {
callback(false,JSON(self.getStatusCodeString(408)),JSON(408))
}
}
})
}`
Usage
let parameters:[String:Data] = [
"image" : UIImagePNGRepresentation(imageProfile)!
]
Http.upload("api/user/upload_profile", parameters: parameters) { (success, json, header) -> Void in
if success {
print(json!)
}else{
print(json!)
}
}
Thanks! i have solved the problem. your code is very optimised & good.
Once agin thanks for sharing.
Purvi Jani
iOS Application Developer
Phone: +919998009783 | Skype: purvi.pardypanda
Pardy Panda Studios
LinkedIn http://linkedin.com/company/pardy-panda-studios | Facebook
http://facebook.com/pardypandastudios | Twitter
http://twitter.com/pardypanda | Youtube http://youtube.com/pardypanda
On Fri, Jan 13, 2017 at 10:00 AM, Mengheang Rat notifications@github.com
wrote:
`func upload(_ url:String, parameters: [String:Data], callback:@escaping
https://github.com/escaping (Bool, JSON?,JSON?) -> Void){let URL2 = try! URLRequest(url: mainUrl+"user/upload_profile", method: .post, headers: head) Alamofire.upload(multipartFormData: { (multipartFormData) in for (key, value) in parameters { multipartFormData.append(value, withName: key, fileName: "picture.png", mimeType: "image/png") } }, with: URL2, encodingCompletion: { (result) in switch result { case .success(let upload, _, _): upload.responseJSON{ response in if let data = response.result.value{ DispatchQueue.main.async { if(response.response?.statusCode == 200){ callback(true, JSON(data), JSON((response.response?.statusCode)!)) } else{ callback(false, JSON(data), JSON((response.response?.statusCode)!)) } } } } case .failure(let encodingError): print(encodingError) DispatchQueue.main.async { callback(false,JSON(self.getStatusCodeString(408)),JSON(408)) } } })}`
Usage
let parameters:[String:Data] = [ "image" : UIImagePNGRepresentation(imageProfile)!
] Http.upload("api/user/upload_profile", parameters: parameters) {
(success, json, header) -> Void in if success { print(json!) }else{
print(json!) } }—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Alamofire/Alamofire/issues/1575#issuecomment-272358539,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVm5JbIv757lFDeuTIwQNDqVD_UAhKCKks5rRv3pgaJpZM4KBTTP
.
--
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. Any
views or opinions expressed are solely those of the sender and do not
necessarily represent those of Pardy Panda Studios. If you have received
this email in error please notify the sender.
alamofire-multipart-upload Image with parameters not working
https://stackoverflow.com/questions/50489453/swift-4-alamofire-multipart-upload-not-working
Stuck up
Most helpful comment
Thanks! i have solved the problem. your code is very optimised & good.
Once agin thanks for sharing.
Purvi Jani
iOS Application Developer
Phone: +919998009783 | Skype: purvi.pardypanda
Pardy Panda Studios
LinkedIn http://linkedin.com/company/pardy-panda-studios | Facebook
http://facebook.com/pardypandastudios | Twitter
http://twitter.com/pardypanda | Youtube http://youtube.com/pardypanda
On Fri, Jan 13, 2017 at 10:00 AM, Mengheang Rat notifications@github.com
wrote:
--
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. Any
views or opinions expressed are solely those of the sender and do not
necessarily represent those of Pardy Panda Studios. If you have received
this email in error please notify the sender.