How to use Android to upload file to server with a key?
I have a server written by Django, and now I have a demand to upload file to this server. I used to do it on iPhone using ASIHttpRequest, the method is pretty straightforward:
[request setFile:self.latestFilePath forKey:@"IPHONEFILE"];
However, after I switched to Android, I tried to look for similar method without any luck.
I am aware of two methods to send data to server, one is BasicNameValuePair with key-value pair, which is not suitabl开发者_Go百科e for my program since the file is huge. Another method is InputStreamEntity, but I don't know how to add a key to it.
Any hint or suggestion would be appreciated!
You can use the class mentioned on this page:
http://moazzam-khan.com/blog/?tag=android-upload-file
Specifically, this method:
/**
* Post request (upload files)
* @param sUrl
* @param params Form data
* @param files
* @return
*/
public static HttpData post(String sUrl,
Hashtable<String, String> params, ArrayList<File> files) {
HttpData ret = new HttpData();
You can specify Keys as part of params.
精彩评论