【发布时间】:2019-04-19 10:11:45
【问题描述】:
我正在尝试通过Alamofire 测试上传速度,将文件文本发送到服务器。尝试了this 和this,但无法成功,我应该为 myFile.txt 使用哪种数据?我需要某个地方的 php 脚本吗?
let parameters = ["file_name": "myFile.txt"]
Alamofire.upload(multipartFormData: { (multipartFormData) in
//I cannot substitute this line of code
// multipartFormData.append(UIImageJPEGRepresentation(self.photoImageView.image!, 1)!, withName: "photo_path", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to:"example.com")
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
//Print progress
print("in progress...")
})
upload.responseJSON { response in
//print response.result
print(response)
}
case .failure(let encodingError):
//print encodingError.description
print("error")
}
【问题讨论】:
-
我找不到你的评论了,你是说 Alamofire 不能上传文件文本吗?你觉得我可以用图片做同样的测试吗?