<legend id='OPJlG'><style id='OPJlG'><dir id='OPJlG'><q id='OPJlG'></q></dir></style></legend>

    1. <small id='OPJlG'></small><noframes id='OPJlG'>

        • <bdo id='OPJlG'></bdo><ul id='OPJlG'></ul>

        <tfoot id='OPJlG'></tfoot>
        <i id='OPJlG'><tr id='OPJlG'><dt id='OPJlG'><q id='OPJlG'><span id='OPJlG'><b id='OPJlG'><form id='OPJlG'><ins id='OPJlG'></ins><ul id='OPJlG'></ul><sub id='OPJlG'></sub></form><legend id='OPJlG'></legend><bdo id='OPJlG'><pre id='OPJlG'><center id='OPJlG'></center></pre></bdo></b><th id='OPJlG'></th></span></q></dt></tr></i><div id='OPJlG'><tfoot id='OPJlG'></tfoot><dl id='OPJlG'><fieldset id='OPJlG'></fieldset></dl></div>

        Android:使用 MultipartEntity 上传大文件

        Android : Upload large files using MultipartEntity(Android:使用 MultipartEntity 上传大文件)
          <tbody id='bMylU'></tbody>

          • <bdo id='bMylU'></bdo><ul id='bMylU'></ul>
            <tfoot id='bMylU'></tfoot>

                <small id='bMylU'></small><noframes id='bMylU'>

                1. <i id='bMylU'><tr id='bMylU'><dt id='bMylU'><q id='bMylU'><span id='bMylU'><b id='bMylU'><form id='bMylU'><ins id='bMylU'></ins><ul id='bMylU'></ul><sub id='bMylU'></sub></form><legend id='bMylU'></legend><bdo id='bMylU'><pre id='bMylU'><center id='bMylU'></center></pre></bdo></b><th id='bMylU'></th></span></q></dt></tr></i><div id='bMylU'><tfoot id='bMylU'></tfoot><dl id='bMylU'><fieldset id='bMylU'></fieldset></dl></div>

                  <legend id='bMylU'><style id='bMylU'><dir id='bMylU'><q id='bMylU'></q></dir></style></legend>
                2. 本文介绍了Android:使用 MultipartEntity 上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据这个答案 "Android 使用 HTTP 多部分表单数据将视频上传到远程服务器"我完成所有步骤.p>

                  但我不知道如何为服务器端编码!我的意思是一个 PHP 简单的页面,为我最可靠的敌人上传服务.

                  另一个问题是:YOUR_URL(以下代码段的第 3 行)必须是那个 PHP 页面的地址?

                  private void uploadVideo(String videoPath) throws ParseException, IOException {HttpClient httpclient = new DefaultHttpClient();HttpPost httppost = 新的 HttpPost(YOUR_URL);FileBody filebodyVideo = new FileBody(new File(videoPath));StringBody title = new StringBody("文件名:" + videoPath);StringBody description = new StringBody("这是视频的描述");MultipartEntity reqEntity = new MultipartEntity();reqEntity.addPart("videoFile", filebodyVideo);reqEntity.addPart("标题", 标题);reqEntity.addPart("描述", 描述);httppost.setEntity(reqEntity);//调试System.out.println("执行请求" + httppost.getRequestLine());HttpResponse 响应 = httpclient.execute( httppost );HttpEntity resEntity = response.getEntity();//调试System.out.println(response.getStatusLine());如果(resEntity!= null){System.out.println(EntityUtils.toString(resEntity));}//万一如果(resEntity!= null){resEntity.consumeContent();}//万一httpclient.getConnectionManager().shutdown();}

                  解决方案

                  这段代码运行正常,我应该使用的 PHP 代码就这么简单:

                  注意 videoFile 必须完全匹配

                  reqEntity.addPart("videoFile", filebodyVideo);

                  您可能面临的最重要问题是服务器配置中 post_max_sizeupload_max_filesize 的默认值!由于默认值太小,当您尝试上传大文件时,PHP 脚本返回:"upload_fail_php_file",没有错误或异常抛出.所以请记住将这些值设置得足够大...

                  享受编码.

                  According this answer "Android upload video to remote server using HTTP multipart form data" I do all steps.

                  But I don't know how I code for server side! I mean a PHP simple page that serve my reauest foe upload.

                  And another question is that : YOUR_URL (3rd line of following snippet) must be address of that PHP page?

                  private void uploadVideo(String videoPath) throws ParseException, IOException {
                  
                      HttpClient httpclient = new DefaultHttpClient();
                      HttpPost httppost = new HttpPost(YOUR_URL);
                  
                      FileBody filebodyVideo = new FileBody(new File(videoPath));
                      StringBody title = new StringBody("Filename: " + videoPath);
                      StringBody description = new StringBody("This is a description of the video");
                  
                      MultipartEntity reqEntity = new MultipartEntity();
                      reqEntity.addPart("videoFile", filebodyVideo);
                      reqEntity.addPart("title", title);
                      reqEntity.addPart("description", description);
                      httppost.setEntity(reqEntity);
                  
                      // DEBUG
                      System.out.println( "executing request " + httppost.getRequestLine( ) );
                      HttpResponse response = httpclient.execute( httppost );
                      HttpEntity resEntity = response.getEntity( );
                  
                      // DEBUG
                      System.out.println( response.getStatusLine( ) );
                      if (resEntity != null) {
                        System.out.println( EntityUtils.toString( resEntity ) );
                      } // end if
                  
                      if (resEntity != null) {
                        resEntity.consumeContent( );
                      } // end if
                  
                      httpclient.getConnectionManager( ).shutdown( );
                  }
                  

                  解决方案

                  This code worked properly and PHP code I should use is as simple as this:

                  <?php
                  
                      $file_path = "uploads/";
                  
                      $file_path = $file_path . basename( $_FILES['videoFile']['name']);
                      if(move_uploaded_file($_FILES['videoFile']['tmp_name'], $file_path)) {
                          echo "success";
                      } else{
                          echo "upload_fail_php_file";
                      }
                   ?>
                  

                  NOTE that videoFile must match exactly with

                  reqEntity.addPart("videoFile", filebodyVideo);

                  And the MOST Important problem you probably face to, is default value of post_max_size and upload_max_filesize in the server config! As default is too small and when you try to upload large files, the PHP script return : "upload_fail_php_file" with no error or exception throwing. So remember to set these values as big as enough...

                  Enjoy coding.

                  这篇关于Android:使用 MultipartEntity 上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <i id='h0nlv'><tr id='h0nlv'><dt id='h0nlv'><q id='h0nlv'><span id='h0nlv'><b id='h0nlv'><form id='h0nlv'><ins id='h0nlv'></ins><ul id='h0nlv'></ul><sub id='h0nlv'></sub></form><legend id='h0nlv'></legend><bdo id='h0nlv'><pre id='h0nlv'><center id='h0nlv'></center></pre></bdo></b><th id='h0nlv'></th></span></q></dt></tr></i><div id='h0nlv'><tfoot id='h0nlv'></tfoot><dl id='h0nlv'><fieldset id='h0nlv'></fieldset></dl></div>
                  <tfoot id='h0nlv'></tfoot>
                      • <bdo id='h0nlv'></bdo><ul id='h0nlv'></ul>

                        <small id='h0nlv'></small><noframes id='h0nlv'>

                            <tbody id='h0nlv'></tbody>

                          • <legend id='h0nlv'><style id='h0nlv'><dir id='h0nlv'><q id='h0nlv'></q></dir></style></legend>