I want to upload and audio file with using Alamofire
. I see other questions which are telling to use Multipart request to do that
Here is the example i got form other question :
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(audioRecorder?.url, withName: "iosTest.mp3")
//**this "withName:" is it the name of the file?
},
to: "https://yourLinkGoesHere",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
)
So when i look at an example above and i did not get a few points to understand.
1) what is "withName:" in this part multipartFormData.append(audioRecorder?.url, withName: "iosTest.mp3")
above? Is it an audio file name in iphone device?
2) Where can i set parameters and headers?
Cause in normal request what i do is like this :
let headers : HTTPHeaders = ["Authorization" : apiKey]
let params : [String : Any] = ["my_param" : myParams]
Alamofire.request(My_URL!, method: .post, parameters: params, encoding: URLEncoding.httpBody, headers: headers).responseJSON {
response in
switch response.result {
So in multipart where should i specific headers and params? Please give some example for multipartFromData.append
part.This part is quite confusing for me.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…