【问题标题】:How to upload Image and Video file using HttpPost in android如何在android中使用HttpPost上传图像和视频文件
【发布时间】:2015-01-17 23:16:44
【问题描述】:

我需要使用 HttpPost 方法上传具有多个参数的图像和视频文件,例如文件名、描述、高度和宽度。

谢谢, 建议表示赞赏。

【问题讨论】:

标签: android file-upload http-post


【解决方案1】:

要上传文件,最有效的方法是使用 HttpPost 和 multipart/form

Multipart/form 文件内容要么存储在内存中,要么临时存储在磁盘上。在任何一种情况下,如果需要,用户负责将文件内容复制到会话级别或持久存储。临时存储将在请求处理结束时被清除

参考这个Upload Files from Android to a Website/Http Server using Post

【讨论】:

    【解决方案2】:

    试试这个代码

      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();
        }
    

    或者也参考这个链接 "http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/" 谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-19
      • 1970-01-01
      相关资源
      最近更新 更多