Sunday, April 20, 2014

Multipartentity upload pictures through, asp.net server how to receive it?


Need to upload pictures, so just use multipartentity, from the Internet to look at the source of the multipartentity not know the code below
 / / upload images to the server 
public String UploadImage (String url, Map param, File file) throws Exception {
String result = "";
HttpPost post = new HttpPost (url);

MultipartEntity entity = new MultipartEntity ();
if (param! = null &&! param.isEmpty ()) {
for (Map.Entry entry: param.entrySet ()) {
if (entry.getValue ()! = null
&& Entry.getValue (). Trim (). Length ()> 0) {
entity.addPart (entry.getKey (), new StringBody (entry.getValue ()));

}
}
}
/ / Add the file parameters
if (file! = null && file.exists ()) {
entity.addPart ("file", new FileBody (file)); / / This file documents how to receive it
}
post.setEntity (entity);

HttpClient httpClient = new DefaultHttpClient ();
/ / Uploading
HttpResponse response = httpClient.execute (post);
/ / StringBuffer sb = new StringBuffer ();

if (response.getStatusLine (). getStatusCode () == HttpStatus.SC_OK) {
result = retrieveInputStream (response.getEntity ());
Log.e ("ykp", "picture upload:" + result);
}

post.abort ();
return result;
}

How Will the asp.net server receives the file documents? Which heroes to a code?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Your problem solved? How to get in?

No comments:

Post a Comment