使用_FILES无法发送文件到PHP服务器服务器、文件、_FILES、PHP

2023-09-05 05:21:53 作者:天会亮心会暖i

我要发送的值到PHP服务器,但一如既往,我得到的HTTP响应200在我的服务器我没有得到我发送的值,不知道什么是下面的问题是我的片断code Android和PHP,任何一个可以帮助我?......对不起得多code ......我也跟着这样的 Android的文件上传 - $ _FILES返回空

PHP端,我用的Smarty框架

  $打印= FALSE;
 $标题= TRUE;
如果(使用isset($ _ REQUEST ['行动'])及和放大器; $ _REQUEST ['行动'] =='imagetest)
{
$错误='0';
$ VAL =基名($ _ FILES ['形象'] ['名称']);
如果($ VAL!='')
{
    $错误='1';
    $味精='图片无法上传请尝试阿欣;
    $参数=阵列(状态=>中的错误,味精=> $ VAL);
    $ VAL = json_en code($参数);
    回声$ VAL;
    出口;
}
/ *如果($ _ FILES ['形象'] =='')
{
    $错误='1';
    $味精='图片无法上传请尝试阿欣;
    $参数=阵列(状态=>中的错误,味精=> $味精);
    $ VAL = json_en code($参数);
    回声$ VAL;
    出口;
} * /
如果($错误== 0)
{

    $ target_path =上传/;

    $ target_path = $ target_path。基本名($ _ FILES ['形象'] ['名称']);

    如果(move_uploaded_file($ _ FILES ['形象'] ['tmp_name的值'],$ target_path)){
        $味精=图像插入成功;
        $参数=阵列(状态=>中成功,味精=> $味精);
        $ VAL = json_en code($参数);
        回声$ VAL;
        出口;
    } 其他{
        $味精='图片没有插入成功;
        $参数=阵列(状态=>中成功,味精=> $味精);
        $ VAL = json_en code($参数);
        回声$ VAL;
        出口;
    }
}
}
 其他
  {
$味精='出事了';
$参数=阵列(状态=>中成功,味精=> $味精);
$ VAL = json_en code($参数);
回声$ VAL;
出口;
  }
 

MyjavaFile

  uploadButton =(ImageView的)findViewById(R.id.uploadButton);
      uploadButton.setOnClickListener(新OnClickListener()
    {
       @覆盖
       公共无效的onClick(视图v)
       {
           对话框= ProgressDialog.show(PhotoUpload.this,,上传文件...,真正的);
           新主题(新的Runnable()
           {
                   公共无效的run()
                   {
                        runOnUiThread(新的Runnable()
                        {
                               公共无效的run()
                               {
                                messageText.setText(上传开始......);
                               }
                           });
                    uploadFile(selectedImagePath);
                   }
                 })。开始();
           }
       });
  }



   @覆盖
     公共无效onActivityResult(INT申请code,INT结果code,意图数据){

   super.onActivityResult(要求code,因此code,数据);
   如果(要求code == 1111){

          如果(数据!= NULL){
                    openGalleryImage(数据);
                    // saveImage(uri_outputFileUri.getPath());
                    乌里selectedImageUri = data.getData();
                    点阵位图;
                    尝试 {
                        位= scaleImage(PhotoUpload.this,selectedImageUri);
                        img.setImageBitmap(位);
                    }赶上(IOException异常E){

                        e.printStackTrace();
                    }

          }
            }

          }

   公共静态位图scaleImage(上下文的背景下,乌里photoUri)抛出IOException异常{
        。InputStream的是= context.getContentResolver()openInputStream(photoUri);
        BitmapFactory.Options DBO =新BitmapFactory.Options();
        dbo.inJustDe codeBounds = TRUE;
        BitmapFactory.de codeStream(是,空,DBO);
        is.close();

        INT rotatedWidth,rotatedHeight;
        INT方向= getOrientation(背景下,photoUri);

        如果(定向== 90 ||方向== 270){
            rotatedWidth = dbo.outHeight;
            rotatedHeight = dbo.outWidth;
        } 其他 {
            rotatedWidth = dbo.outWidth;
            rotatedHeight = dbo.outHeight;
        }

        位图srcBitmap;
        ,是= context.getContentResolver()openInputStream(photoUri);
        如果(rotatedWidth大于100 || rotatedHeight→100){
            浮动widthRatio =((浮点)rotatedWidth)/((浮动)×100);
            浮动heightRatio =((浮点)rotatedHeight)/((浮动)×100);
            浮maxRatio = Math.max(widthRatio,heightRatio);

            //从文件创建位图
            BitmapFactory.Options选项=新BitmapFactory.Options();
            options.inSampleSize =(INT)maxRatio;
            srcBitmap = BitmapFactory.de codeStream(是,空,期权);
        } 其他 {
            srcBitmap = BitmapFactory.de codeStream(是);
        }
        is.close();


        如果(取向&0){
            字模=新的Matrix();
            matrix.postRotate(方向);

            srcBitmap = Bitmap.createBitmap(srcBitmap,0,0,srcBitmap.getWidth(),
                    srcBitmap.getHeight(),矩阵,真正的);
        }

        字符串类型= context.getContentResolver()的getType(photoUri)。
        ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
        如果(type.equals(图像/ PNG)){
            srcBitmap.com preSS(Bitmap.Com pressFormat.PNG,100,BAOS);
        }否则,如果(type.equals(图像/ JPG)|| type.equals(为image / jpeg)){
            srcBitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);
        }
        byte []的bMapArray = baos.toByteArray();
        baos.close();
        返回BitmapFactory.de codeByteArray(bMapArray,0,bMapArray.length);
    }

    公共静态INT getOrientation(上下文的背景下,乌里photoUri){
        / *这是外部媒体。 * /
        光标光标= context.getContentResolver()查询(photoUri,
                新的String [] {} MediaStore.Images.ImageColumns.ORIENTATION,NULL,NULL,NULL);

        如果(cursor.getCount()!= 1){
            返回-1;
        }

        cursor.moveToFirst();
        返回cursor.getInt(0);
    }
    私人无效openGalleryImage(意图数据)
    {
        乌里selectedimg = data.getData();
        乌里uriselectedimage = data.getData();
        mString = uriselectedimage.getPath();
        尝试
        {
            mInputStream = getContentResolver()openInputStream(selectedimg)。
        }
        赶上(FileNotFoundException异常E)
        {
            e.printStackTrace();
        }

        的String []路径= {MediaStore.Images.Media.DATA};
        光标C = getContentResolver()查询(selectedimg,路径,NULL,NULL,NULL);
        c.moveToFirst();
        INT参数:columnIndex = c.getColumnIndex(路径[0]);
        selectedImagePath = c.getString(参数:columnIndex);
        uri_outputFileUri = Uri.parse(selectedImagePath);
        c.close();
    }

    私人无效saveImage(字符串的mpath)
    {

        的System.out.println(路径+的mpath);
            mediaDir =新的文件(Environment.getExternalStorageDirectory()+/ MyFolder的);
            mediaDir.mkdir();


        文件MYIMAGE =新的文件(mediaDir,Long.toString(System.currentTimeMillis的())+巴纽);

        尝试
        {
            FileOutputStream中出=新的FileOutputStream(MYIMAGE);
            mbitmap_outputImage = BitmapFactory.de codeFILE(的mpath);
            mbitmap_outputImage = Bitmap.createScaledBitmap(mbitmap_outputImage,390,310,真正的);
            mbitmap_outputImage.com preSS(Bitmap.Com pressFormat.PNG,100,出);
            img.setImageBitmap(mbitmap_outputImage);
            了out.flush();
            out.close();

        }
        赶上(例外五)
        {
            e.printStackTrace();
        }

    }

      @燮pressWarnings(德precation)
         公共字符串getPath(URI URI){
   的String []投影= {MediaStore.Images.Media.DATA};
   光标光标= managedQuery(URI,投影,NULL,NULL,NULL);
   INT与Column_Index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
   cursor.moveToFirst();
   返回cursor.getString(Column_Index中);
 }

公众诠释uploadFile(字符串sourceFileUri){


     DataOutputStream类DOS = NULL;
     字符串lineEnd =\ r \ N的;
     串twoHyphens = - ;
     字符串边界=*****;
     INT读取动作,方bytesAvailable,缓冲区大小;
     byte []的缓冲区;
     INT maxBufferSize = 1 * 1024 * 1024;
     文件的SourceFile =新的文件(sourceFileUri);


     如果(!sourceFile.isFile()){

           dialog.dismiss();

           Log.e(一个UploadFile,源文件不存在
                               + selectedImagePath);


           runOnUiThread(新的Runnable(){
               公共无效的run(){
                   messageText.setText(源文件不存在
                           + selectedImagePath);
               }
           });

           返回0;
     }
     其他
     {
           尝试 {
                 / * btns = uploadButton.getTag()的toString();
                的System.out.println(btns); * /
                  字符串文件名= sourceFileUri;
                  文件F =新的文件(selectedImagePath);
                 IMGS = f.getName();
                的System.out.println(IMGS);

                upLoadServerUri =htt​​p://www.asdf.com/web-service/imagetest.php?action=imagetest&image="+imgs;


                 //打开一个URL连接到这个Servlet


               的FileInputStream的FileInputStream =新的FileInputStream(的资源文件);
               网址URL =新的URL(upLoadServerUri);
               的System.out.println(URL);
               //打开一个HTTP连接网址
               康恩=(HttpURLConnection类)url.openConnection();
               conn.setDoInput(真正的); //允许输入
               conn.setDoOutput(真正的); //允许输出
               conn.setUseCaches(假); //不要使用缓存副本
                                   conn.setRequestMethod(POST);

                   conn.setRequestProperty(连接,保持活动);
                   conn.setRequestProperty(ENCTYPE,多部分/表单数据);
                   conn.setRequestProperty(内容类型,多部分/格式数据;边界=+界);
                   conn.setRequestProperty(形象,IMGS);
                 // conn.setRequestProperty(user_login_id,USER_ID);
                  // conn.setRequestProperty(行动,addproduct);
                  // conn.setRequestProperty(版本,应用程序);

               DOS =新DataOutputStream类(conn.getOutputStream());

                 //添加参数
                 dos.writeBytes(twoHyphens +边界+ lineEnd);
                    dos.writeBytes(内容处置:表格数据;名称= \类型\
                         + lineEnd);
                 dos.writeBytes(lineEnd);

                 //分配值


                    //发送图片
                 dos.writeBytes(twoHyphens +边界+ lineEnd);
                 dos.writeBytes(内容处置:表格数据;名称=形象;文件名='
                         + IMGS +'+ lineEnd);

                 dos.writeBytes(lineEnd);

               //创建最大大小的缓冲区
               方bytesAvailable = fileInputStream.available();

               BUFFERSIZE = Math.min(方bytesAvailable,maxBufferSize);
               缓冲区=新的字节[BUFFERSIZE]

               //读取文件,并将其写入形式...
               读取动作= fileInputStream.read(缓冲液,0,BUFFERSIZE);

               而(读取动作大于0){

                 dos.write(缓冲液,0,BUFFERSIZE);
                 方bytesAvailable = fileInputStream.available();
                 BUFFERSIZE = Math.min(方bytesAvailable,maxBufferSize);
                 读取动作= fileInputStream.read(缓冲液,0,BUFFERSIZE);

                }

               //发送多部分表格数据文件数据后necesssary ...
               dos.writeBytes(lineEnd);
               dos.writeBytes(twoHyphens +边界+ twoHyphens + lineEnd);

               从服务器//回应(code和消息)
               serverResponse code = conn.getResponse code();
               串serverResponseMessage = conn.getResponseMessage();

               Log.i(一个UploadFile,HTTP响应是:
                       + serverResponseMessage +:+ serverResponse code);

               如果(serverResponse code == 200){

                   runOnUiThread(新的Runnable(){
                        @燮pressWarnings(德precation)
                        公共无效的run(){


                            尝试
                            {


                                DATAIN的DataInputStream =新的DataInputStream(conn.getInputStream());
                                字符串inputLine;
                                而((inputLine = dataIn.readLine())!= NULL)
                                {
                                    结果+ = inputLine;
                                    的System.out.println(结果:+结果);
                                }
                                //结果= getJSONUrl(URL); //<<从服务器JSON字符串
                                //的JSONObject的JSONObject =新的JSONObject的(结果);
                                JSONObject的jobj =新的JSONObject的(结果);
                                STA = jobj.getString(状态);
                                味精= jobj.getString(味精);
                                的System.out.println(STA +>>>>>>>+味精);

                               //新LoadImages()执行()。
                               / *意向意图=新的意图(PhotoUpload.this,PhotoView.class);
                                startActivity(意向); * /



                            }
                            赶上(例外五)
                            {
                                e.printStackTrace();
                            }
 

解决方案 怎么把本机上的文件传到服务器上

您可以参考这个很好的教程 Android的上载摄像机的图像,视频与进度条服务器

I am trying to send values to PHP server but always,i get HTTP REsponse 200 and in my server i am not getting the value i sent,dont know what is the issue following is my snippet code for android and PHP,can any one help me with this?..sorry for to much code......i also followed this Android file upload - $_FILES returns empty

PHP side i used smarty framework

 $print = false;
 $header = true;
if(isset($_REQUEST['action']) && $_REQUEST['action'] =='imagetest')
{ 
$error = '0';
$val = basename($_FILES['image']['name']);
if($val != '')
{
    $error = '1';
    $msg = 'Image Not Upload Please Try Agin';
    $param = array("status"=>"error","msg"=>$val);
    $val = json_encode($param);
    echo $val;
    exit;
}
/*if($_FILES['image'] == '')
{
    $error = '1';
    $msg = 'Image Not Upload Please Try Agin';
    $param = array("status"=>"error","msg"=>$msg);
    $val = json_encode($param);
    echo $val;
    exit;
}*/
if($error == '0')
{ 

    $target_path = "uploads/";

    $target_path = $target_path . basename( $_FILES['image']['name']);

    if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
        $msg = 'Image inserted successfully';
        $param = array("status"=>"success","msg"=>$msg);
        $val = json_encode($param);
        echo $val;
        exit;
    } else{
        $msg = 'Image not inserted successfully';
        $param = array("status"=>"success","msg"=>$msg);
        $val = json_encode($param);
        echo $val;
        exit;
    }
}
}
 else
  {
$msg = 'something went wrong';
$param = array("status"=>"success","msg"=>$msg);
$val = json_encode($param);
echo $val;
exit;
  }

MyjavaFile

   uploadButton = (ImageView)findViewById(R.id.uploadButton);
      uploadButton.setOnClickListener(new OnClickListener() 
    {            
       @Override
       public void onClick(View v) 
       {
           dialog = ProgressDialog.show(PhotoUpload.this, "", "Uploading file...", true);
           new Thread(new Runnable()
           {
                   public void run() 
                   {
                        runOnUiThread(new Runnable() 
                        {
                               public void run() 
                               {
                                messageText.setText("uploading started.....");
                               }
                           });                      
                    uploadFile(selectedImagePath);                       
                   }
                 }).start();        
           }
       });
  }



   @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {

   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == 1111) {

          if (data!=null ) {
                    openGalleryImage(data);
                    //saveImage(uri_outputFileUri.getPath());
                    Uri selectedImageUri = data.getData();
                    Bitmap bitmap;
                    try {
                        bitmap = scaleImage(PhotoUpload.this,selectedImageUri);
                        img.setImageBitmap(bitmap);
                    } catch (IOException e) {

                        e.printStackTrace();
                    }         

          }
            }

          }

   public static Bitmap scaleImage(Context context, Uri photoUri) throws IOException {
        InputStream is = context.getContentResolver().openInputStream(photoUri);
        BitmapFactory.Options dbo = new BitmapFactory.Options();
        dbo.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, dbo);
        is.close();

        int rotatedWidth, rotatedHeight;
        int orientation = getOrientation(context, photoUri);

        if (orientation == 90 || orientation == 270) {
            rotatedWidth = dbo.outHeight;
            rotatedHeight = dbo.outWidth;
        } else {
            rotatedWidth = dbo.outWidth;
            rotatedHeight = dbo.outHeight;
        }

        Bitmap srcBitmap;
        is = context.getContentResolver().openInputStream(photoUri);
        if (rotatedWidth > 100 || rotatedHeight > 100) {
            float widthRatio = ((float) rotatedWidth) / ((float) 100);
            float heightRatio = ((float) rotatedHeight) / ((float) 100);
            float maxRatio = Math.max(widthRatio, heightRatio);

            // Create the bitmap from file
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = (int) maxRatio;
            srcBitmap = BitmapFactory.decodeStream(is, null, options);
        } else {
            srcBitmap = BitmapFactory.decodeStream(is);
        }
        is.close();


        if (orientation > 0) {
            Matrix matrix = new Matrix();
            matrix.postRotate(orientation);

            srcBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(),
                    srcBitmap.getHeight(), matrix, true);
        }

        String type = context.getContentResolver().getType(photoUri);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (type.equals("image/png")) {
            srcBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        } else if (type.equals("image/jpg") || type.equals("image/jpeg")) {
            srcBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        }
        byte[] bMapArray = baos.toByteArray();
        baos.close();
        return BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
    }

    public static int getOrientation(Context context, Uri photoUri) {
        /* it's on the external media. */
        Cursor cursor = context.getContentResolver().query(photoUri,
                new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

        if (cursor.getCount() != 1) {
            return -1;
        }

        cursor.moveToFirst();
        return cursor.getInt(0);
    }
    private void openGalleryImage(Intent data) 
    {
        Uri selectedimg = data.getData();
        Uri uriselectedimage=data.getData();
        mString=uriselectedimage.getPath();
        try 
        {
            mInputStream= getContentResolver().openInputStream(selectedimg);
        }
        catch (FileNotFoundException e) 
        {
            e.printStackTrace();
        }

        String[] path = { MediaStore.Images.Media.DATA };
        Cursor c =  getContentResolver().query(selectedimg, path, null, null,null);
        c.moveToFirst();
        int columnIndex = c.getColumnIndex(path[0]);
        selectedImagePath=c.getString(columnIndex);
        uri_outputFileUri= Uri.parse(selectedImagePath);
        c.close();
    }

    private void saveImage(String mPath) 
    {

        System.out.println("Paths  "+mPath);
            mediaDir= new File(Environment.getExternalStorageDirectory() +"/MyFolder");
            mediaDir.mkdir();


        File myImage = new File(mediaDir, Long.toString(System.currentTimeMillis()) + ".png");

        try 
        { 
            FileOutputStream out = new FileOutputStream(myImage);
            mbitmap_outputImage=BitmapFactory.decodeFile(mPath);    
            mbitmap_outputImage=Bitmap.createScaledBitmap(mbitmap_outputImage, 390, 310, true);
            mbitmap_outputImage.compress(Bitmap.CompressFormat.PNG, 100, out); 
            img.setImageBitmap(mbitmap_outputImage);
            out.flush();    
            out.close();

        } 
        catch (Exception e)
        { 
            e.printStackTrace(); 
        }  

    }    

      @SuppressWarnings("deprecation")
         public String getPath(Uri uri) {
   String[] projection = { MediaStore.Images.Media.DATA };
   Cursor cursor = managedQuery(uri, projection, null, null, null);
   int column_index =    cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
   cursor.moveToFirst();
   return cursor.getString(column_index);
 }

public int uploadFile(String sourceFileUri) {


     DataOutputStream dos = null;  
     String lineEnd = "\r\n";
     String twoHyphens = "--";
     String boundary = "*****";
     int bytesRead, bytesAvailable, bufferSize;
     byte[] buffer;
     int maxBufferSize = 1 * 1024 * 1024; 
     File sourceFile = new File(sourceFileUri); 


     if (!sourceFile.isFile()) {

           dialog.dismiss(); 

           Log.e("uploadFile", "Source File not exist :"
                               + selectedImagePath);


           runOnUiThread(new Runnable() {
               public void run() {
                   messageText.setText("Source File not exist :"
                           + selectedImagePath);
               }
           }); 

           return 0;
     }
     else
     {
           try { 
                 /* btns=uploadButton.getTag().toString();
                System.out.println(btns);*/
                  String fileName = sourceFileUri;
                  File f  = new File(selectedImagePath);
                 imgs= f.getName();
                System.out.println(imgs);

                upLoadServerUri = "http://www.asdf.com/web-service/imagetest.php?action=imagetest&image="+imgs;


                 // open a URL connection to the Servlet


               FileInputStream fileInputStream = new FileInputStream(sourceFile);
               URL url = new URL(upLoadServerUri);
               System.out.println(url);
               // Open a HTTP  connection to  the URL
               conn = (HttpURLConnection) url.openConnection(); 
               conn.setDoInput(true); // Allow Inputs
               conn.setDoOutput(true); // Allow Outputs
               conn.setUseCaches(false); // Don't use a Cached Copy
                                   conn.setRequestMethod("POST");

                   conn.setRequestProperty("Connection", "Keep-Alive");
                   conn.setRequestProperty("ENCTYPE", "multipart/form-data");
                   conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
                   conn.setRequestProperty("image", imgs);
                 //  conn.setRequestProperty("user_login_id", User_ID);
                  // conn.setRequestProperty("action", "addproduct");
                  // conn.setRequestProperty("version", "apps");

               dos  = new DataOutputStream(conn.getOutputStream());

                 // add parameters
                 dos.writeBytes(twoHyphens + boundary + lineEnd);
                    dos.writeBytes("Content-Disposition: form-data; name=\"type\""
                         + lineEnd);
                 dos.writeBytes(lineEnd);

                 // assign value


                    // send image
                 dos.writeBytes(twoHyphens + boundary + lineEnd); 
                 dos.writeBytes("Content-Disposition: form-data; name='image';filename='"
                         + imgs + "'" + lineEnd);

                 dos.writeBytes(lineEnd);

               // create a buffer of  maximum size
               bytesAvailable = fileInputStream.available(); 

               bufferSize = Math.min(bytesAvailable, maxBufferSize);
               buffer = new byte[bufferSize];

               // read file and write it into form...
               bytesRead = fileInputStream.read(buffer, 0, bufferSize);  

               while (bytesRead > 0) {

                 dos.write(buffer, 0, bufferSize);
                 bytesAvailable = fileInputStream.available();
                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
                 bytesRead = fileInputStream.read(buffer, 0, bufferSize);   

                }

               // send multipart form data necesssary after file data...
               dos.writeBytes(lineEnd);
               dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

               // Responses from the server (code and message)
               serverResponseCode = conn.getResponseCode();
               String serverResponseMessage = conn.getResponseMessage();

               Log.i("uploadFile", "HTTP Response is : " 
                       + serverResponseMessage + ": " + serverResponseCode);

               if(serverResponseCode == 200){

                   runOnUiThread(new Runnable() {
                        @SuppressWarnings("deprecation")
                        public void run() {


                            try 
                            {


                                DataInputStream dataIn = new DataInputStream(conn.getInputStream());
                                String inputLine;
                                while ((inputLine = dataIn.readLine()) != null) 
                                {
                                    result += inputLine;
                                    System.out.println("Result : " + result);
                                }
                                //result=getJSONUrl(url);  //<< get json string from server
                                //JSONObject jsonObject = new JSONObject(result);
                                JSONObject jobj = new JSONObject(result);
                                sta = jobj.getString("status");
                                msg = jobj.getString("msg");
                                System.out.println(sta + " >>>>>>> " + msg);

                               // new LoadImages().execute();
                               /* Intent intent=new Intent(PhotoUpload.this,PhotoView.class);
                                startActivity(intent);*/



                            } 
                            catch (Exception e) 
                            {
                                e.printStackTrace();
                            }

解决方案

you can refer this nice tutorial "Android Uploading Camera Image, Video to Server with Progress Bar"