How to upload Image and Video file using HttpPost in android

与世无争的帅哥 提交于 2019-12-22 05:59:13

问题


I need to upload Image and Video File with multiple parameters like File Name, Description , Height and Width using HttpPost method.

Thanks, Suggestion appreciated.


回答1:


For uploading a file the efficient way is using HttpPost with multipart/form

Multipart/form The file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired. The temporary storages will be cleared at the end of request processing

Refer this Upload Files from Android to a Website/Http Server using Post




回答2:


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 refer this link "http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/" Thanks



来源:https://stackoverflow.com/questions/27033764/how-to-upload-image-and-video-file-using-httppost-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!