Alamofire上传“名称”参数

时间:2016-06-16 14:36:21

标签: ios swift alamofire

在Alamofire upload代码中,有一个namefileName字段。

Alamofire.upload(
                    .POST,
                    "http://192.168.1.241:8080/file/user",
                    multipartFormData: { multipartFormData in
                        multipartFormData.appendBodyPart(data: imageData, name: "file", fileName: "file", mimeType: "image/jpeg")
                    },
                    encodingCompletion: { encodingResult in
                        switch encodingResult {
                        case .Success(let upload, _, _):
                            upload.progress { bytesWritten, totalBytesWritten, totalBytesExpectedToWrite in
                                dispatch_async(dispatch_get_main_queue()) {
                                    let percent = (Float(totalBytesWritten) / Float(totalBytesExpectedToWrite))
                                    //progress(percent: percent)
                                    print(percent)
                                }
                            }
                            upload.responseJSON { response in
                                debugPrint(response)
                            }
                        case .Failure(let encodingError):
                            debugPrint(encodingError)
                        }
                    }
                    )

在我的Spring服务器中,我正在寻找@RequestParam("file") MultipartFile file而我无法让它工作,因为我将name设置为file。但显然我需要将fileName设置为"file"

name的目的究竟是什么,如果它似乎没有用于请求参数映射?

1 个答案:

答案 0 :(得分:1)

对于“文件”,它表示文件的完整NSURL属性(例如:www.mysite.com/myvideo.mp4),用于“文件名“只有lastPathComponent String格式(例如:video.mp4)