我想设置几个名为" file"的文件,但实际上我只有一个文件。 使用Alamofire.upload multipartFormData上传文件时遇到一些问题。我需要将Java几个文件上传到一个请求名称中。
例如我使用:
Alamofire.upload(.POST,URLs.publishTopic_url,
multipartFormData: { multipartFormData in
for i in 0 ..< files.count {
multipartFormData.appendBodyPart(data: files[i], name: "file[]", fileName: "\(i)\(NSUUID().UUIDString).jpg", mimeType: "image/jpeg")
}
for (key, value) in parameters {
multipartFormData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding)!, name: key)
}
},
encodingCompletion: { encodingResult in
// Handle result
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
let result = response.result.value
let json = JSON(result!)
print(json)
if json["code"].string! == "200"{
success(message: json["message"].string!)
}else{
failure(message:"上传失败,请稍后重试!")
}
}
case .Failure(let encodingError):
print(encodingError)
}
}
)