【发布时间】:2016-06-17 01:29:26
【问题描述】:
在 Alamofire upload 代码中有一个 name 和 fileName 字段。
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 似乎没有用于请求参数映射,那么它的用途究竟是什么?
【问题讨论】: