apache httpclient4 how to achieve simultaneously upload multiple files
httpclient3 can simultaneously achieve multiple file upload via MultipartRequestEntity, httpclient4 find this class, and did not find a similar approach. Will httpclient4 how to achieve multi-file upload.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: up up up Reply:
request = new HttpPost (url);
MultipartEntity me = new MultipartEntity (); if (parameter! = null && parameter.size ()> 0) {
while (strings.hasNext ()) { Entry entry = strings.next (); String key = entry.getKey (); Object value = entry.getValue ();
if (value instanceof FileBody) { me.addPart (key, (ContentBody) value); } Else { me.addPart (key, new StringBody (value.toString (), Charset.forName ("utf-8"))); } / * if (value instanceof FileModel) {/ / if passed in the file FileModel fileMode = (FileModel) value; File targetFile = new File (fileMode.filePath); if (targetFile.exists ()) { me.addPart ("imgData", new FileBody (targetFile, "image / jpeg", "utf-8")); } } Else { me.addPart (key, new StringBody (value.toString (), Charset.forName ("utf-8"))); } * / } } request.setEntity (me); request.getParams () setParameter (CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);. request.getParams () setParameter (CoreConnectionPNames.SO_TIMEOUT, readTimeout);. / / HttpClient.getHttpConnectionManager () getParams () setConnectionTimeout (5000);.. if (BuildConfig.DEBUG) { Log.d (tag, "post url:" + url); } HttpResponse response = httpClient.execute (request); int statusCode = response.getStatusLine () getStatusCode ();. / / Int statusCode = response.getStatusLine () getStatusCode ();.
Reply:
MultipartEntity this comes apache api in android can not find, I re under a httpclient4.x the jar package, there is this kind of Reply: This can only be a way to pass a file, will cover the previous value of the KEY
No comments:
Post a Comment