6
我试图从Android上传图像到我的Rails服务器。我所有的其他数据上传,但我得到一个“错误无效的身体大小”错误。它与形象有关。以下是我的代码。帮帮我?!使用PaperClip将图像从Android上传到Rails服务器
public void post(String url) {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("content_type","image/jpeg");
try {
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("picture_file_name", new StringBody("damage.jpg"));
File file = new File((imageUri.toString()));
entity.addPart("picture", new FileBody(file, "image/jpeg"));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost, localContext);
} catch (IOException e) {
e.printStackTrace();
}
}
我试过删除浏览器兼容参数,但它没有帮助。我的图像被存储为一个名为imageUri的URI。我使用回形针宝石。
谢谢!