简体   繁体   English

如何在Android中使用HttpPost上传图像和视频文件

[英]How to upload Image and Video file using HttpPost in android

I need to upload Image and Video File with multiple parameters like File Name, Description , Height and Width using HttpPost method. 我需要使用HttpPost方法上传具有多个参数(例如文件名,描述,高度和宽度)的图像和视频文件。

Thanks, Suggestion appreciated. 谢谢,建议表示赞赏。

For uploading a file the efficient way is using HttpPost with multipart/form 要上传文件,有效的方法是将HttpPost与multipart / form一起使用

Multipart/form The file contents are either stored in memory or temporarily on disk. Multipart / form文件内容存储在内存中或临时存储在磁盘上。 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 使用Post将这个从Android上传文件到网站/ Http服务器

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 或也参考此链接“ http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/ ”谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM