Android Upload Multi Files To Server Via Http Post March 17, 2024 Post a Comment I need to upload file from Android client to an URL via HTTP POST. If upload just 1 file, than it is OK for me. but my target URL page code is looks like following Solution 1: I tried following code and confirm that's workable solution:StringBuffer responseBody=newStringBuffer(); Log.i(Constants.TAG, "Ready to upload file..."); HttpClient client=newDefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); Log.i(Constants.TAG, "Set remote URL..."); HttpPost post=newHttpPost("http://IP.IP.IP.IP/file_upload.php"); MultipartEntity entity=newMultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); Log.i(Constants.TAG, "Adding file(s)..."); entity.addPart("uploadedfile", newFileBody((FileObj), "application/zip")); entity.addPart("uploadedfile2", newFileBody((FileObj), "application/zip")); Log.i(Constants.TAG, "Set entity..."); post.setEntity(entity); BufferedReader bs=null; try { Log.i(Constants.TAG, "Upload..."); HttpEntity hEntity=client.execute(post).getEntity(); bs=newBufferedReader(newInputStreamReader(hEntity.getContent())); Log.i(Constants.TAG, "Response length - "+hEntity.getContentLength()); String s=""; while(s!=null) { responseBody.append(s); s=bs.readLine(); Log.i(Constants.TAG, "Response body - "+s); } bs.close(); } catch(IOException ioe) { Log.i(Constants.TAG, "Error on getting response from Server, "+ioe.toString()); ioe.printStackTrace(); responseBody.append("..."); } CopyMy platform is Android 2.2, and use this solution need to get httpmime.jar as project library. Share Post a Comment for "Android Upload Multi Files To Server Via Http Post"
Post a Comment for "Android Upload Multi Files To Server Via Http Post"