How to upload image and video file using HttpPost in android

I need to upload Image and Video File using several parameters, such as file name, description, height and width, using the HttpPost method.

Thanks, The offer is appreciated.

+5
source share
2 answers

To upload a file, an efficient way is to use HttpPost with multipart / form

Multipage / form . The contents of the file are either stored in memory or temporarily on disk. In any case, the user is responsible for copying the contents of the file at the session level or in persistent storage, if necessary. Temporary storage will be cleared at the end of request processing

Refer to Uploading files from Android to website / Http server using message

+4
source

try this code

HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(URL); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); //Path of the file to be uploaded String filepath = params[0]; File file = new File(filepath); ContentBody cbFile = new FileBody(file, SET_MIMETYPE);//"audio/basic" try { mpEntity.addPart(FILE_NAME, cbFile); post.setEntity(mpEntity); HttpResponse response1 = client.execute(post); HttpEntity resEntity = response1.getEntity(); } catch (Exception e) { e.printStackTrace(); } 

or also link to this link " http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/ " Thanks

+1
source

Source: https://habr.com/ru/post/1207279/


All Articles