【发布时间】:2018-02-12 07:31:53
【问题描述】:
我有时想在我的项目中使用 alamo fire 上传多部分图像,而 alamo fire 文件名无缘无故返回 nil - 我该如何避免这种情况?
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")
请记住,有时它会起作用我不知道为什么会发生这种情况!
【问题讨论】:
-
您是否在上传功能中设置了标头值?
-
是的,请稍等,我会将其添加到我的代码中
标签: ios swift3 alamofire filenames image-uploading