I\'m trying to upload an image file via http post method from android device to rails server. But posting an image is not working. More specifically, the post parameter (inc
Sorry, that was my silly mistake. I should have done
params.put("picture[image]", new File(Environment.getExternalStorageDirectory().getPath() + "/Pictures/CameraApp/test.jpg"));
not
params.put("picture[image]", File(Environment.getExternalStorageDirectory().getPath() + "/Pictures/CameraApp/test.jpg"));
Should use New File not File
When using Android Asynchronous Http Client (http://loopj.com/android-async-http/), we don't have to care about MultipartEntity. Thank you to all guys who answered my question!!!!
You can upload the Images via the MultipartEntity.
MultipartEntity, part of HttpMime 4.0 and later. Allows you to put multiple parts, separated by boundary strings and encoded using given charset, into httppost request.
For more info and how to use Multipart, see this and this.
There's a description like below, in Android AsyncHttpClient official page (http://loopj.com/android-async-http/)
"Multipart file uploads with no additional third party libraries"
and in the section of "Uploading Files with RequestParams", they have a sample code to upload an image
File myFile = new File("/path/to/file.png");
RequestParams params = new RequestParams();
try {
params.put("profile_picture", myFile);
} catch(FileNotFoundException e) {}
This is what I did, though didn't work. Does this help answering my question?