• 使用HttpUtils 上传视频文件


    private void shangchuan(){
            
             //文件的路径
            //File file=new File(path);
            File file=new File(Environment.getExternalStorageDirectory()+"/dd.mp4");
            //File file=new File(Environment.getExternalStorageDirectory()+"/"+System.currentTimeMillis()+".mp4");
          

         HttpUtils httpUtils=new HttpUtils();
            RequestParams params=new RequestParams();
            SharedPreferences sp=getSharedPreferences("aa", Context.MODE_PRIVATE);
            String userId=sp.getString("userid", "");


            if (TextUtils.isEmpty(userId)) {
                 Toast.makeText(TakeVideoActivity.this, "请重新登录", Toast.LENGTH_SHORT).show();
                    return;
            }
           //给的接口
            params.addBodyParameter("userid", userId);
            params.addBodyParameter("file", file);
            httpUtils.send(HttpMethod.POST, shangchuanUrl, params, new RequestCallBack<String>() {

                @Override
                public void onFailure(HttpException arg0, String arg1) {
                    Toast.makeText(TakeVideoActivity.this, "上传成功!!!", Toast.LENGTH_LONG).show();
                    
                }

                @Override
                public void onSuccess(ResponseInfo<String> arg0) {
                    System.out.println("上传结果:"+arg0.result);
                    Log.i("上传结果:", arg0.result);
                }
                
                @Override
                public void onLoading(long total, long current, boolean isUploading) {
                    // TODO Auto-generated method stub
                    super.onLoading(total, current, isUploading);
                    System.out.println(""+current+"/"+total);
                }
                
            });
            
        }

  • 相关阅读:
    Codeforces 1072
    XDOJ 1046
    BZOJ 1002
    BZOJ 1001
    BZOJ 1500/Luogu 2042
    nowcoder 211B
    BZOJ 3224
    BZOJ 1150
    POJ 2442
    二叉堆和二叉搜索树进阶
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/5788383.html
Copyright © 2020-2023  润新知