Trouble Uploading Image from Android to Rails Server Using PaperClip

Viewed 2307

I'm trying to upload images to my rails server from Android. All my other data uploads, but I get a "Error invalid body size" error. It has to do with the image. Below is my code. Help?!

 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();
            }
        }

I've tried removing the browser compatible parameter, but it doesn't help. my image is being stored as an URI called imageUri. I'm using paperclip gem.

thanks!

1 Answers
Related