我想用alamo fire在我的项目中多次上传多部分图像,没有理由alamo fire文件名将返回零 - 我该如何避免这种情况?为什么文件名会在alamo中返回零,在swift 3中上传图片?
let params: Parameters = ["name": "image\(i)"]
Alamofire.upload(multipartFormData:
{
(multipartFormData) in
multipartFormData.append(UIImageJPEGRepresentation(imageUploadingViewController.imageUpload[i], 1.0)!, withName: "myfile", fileName: "file.jpeg", mimeType: "image/jpeg")
for (key, value) in params
{
multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
}
}, to: "http:example.com/api/file?api_token=\(enterViewController.api_token)&id=\(self.postID)",headers:nil)
{ (result) in
switch result {
case .success(let upload,_,_):
upload.uploadProgress(closure: { (progress) in
UploadingViewController.progressing = progress.fractionCompleted
self.UpdateState()
if progress.fractionCompleted == 1.0 {
DispatchQueue.main.async {
UploadingViewController.fine = UploadingViewController.fine + 1
}
print(UploadingViewController.fine)
self.checkUploadProgress()
print("OK Finished!")
}
})
应用程序将在此行中崩溃,因为文件名
multipartFormData.append(UIImageJPEGRepresentation(UploadingImagesViewController.imageUpload[i], 1.0)!, withName: "myfile", fileName: "file.jpeg", mimeType: "image/jpeg")
的记住,有些时候它会工作,我不知道为什么会出现这种情况!
你是否在上传函数中设置了标题和值? –
是的请等待,我会将它添加到我的代码 –