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。我使用回形針寶石。
謝謝!