Uploading an image from Android (with Android Asynchronous Http Client) to rails server (with paperclip)

萝らか妹 提交于 2019-11-28 17:39:33
Ryo

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!!!!

Shrikant

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!