-1
的图像时,我能够将图像张贴到Rails应用程序没有问题“的UTF-8无效字节序列”:上传与Alamofire
curl -v include --form [email protected] https://my_url_goes_here.com/path/to/imageupload
...但是当我尝试上传与Alamofire.upload,我看到服务器上的'UTF-8'无效字节序列'错误,并没有保存。
'image'是一个有效的UIImage。
let pictureData = UIImageJPEGRepresentation(image!, 0.8)
Alamofire.upload(.POST, "https://my_url_goes_here.com/path/to/imageupload", pictureData)
.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
println(totalBytesWritten)
}
.responseJSON { (request, response, JSON, error) in
println(JSON)
}
}
Alamofire.upload应该采取的NSData作为参数(可能试图上传之前适当地进行编码),所以我不知道发生了什么错在这里。
除非图像数据在Base64中,否则它不可能是UTF8。 – 2014-12-04 17:20:33
你是如何指定MIME类型的? – 2014-12-04 19:57:39
@HotLicks都好点 - 虽然我预计Alamofire.upload至少会自动将NSData编码到Base64中,以便可以安全地上传。我也希望它适当地处理MIME类型,但也许它不会 - 我会深入一点。感谢您的想法。 – bennettk 2014-12-04 22:09:13