zoukankan      html  css  js  c++  java
  • 使用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);
                }
                
            });
            
        }

  • 相关阅读:
    Django【二】自定义web框架
    Django【一】web框架的本质
    Django【零】HTTP协议
    【前端】bootstrap引入
    【前端】jquery基础学习
    socket模块粘包现象理解以及解决思路
    面向对象编程学习笔记
    socket模块
    CPU缓存体系对Go程序的影响
    测试Go代码 单元测试
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/5788383.html
Copyright © 2011-2022 走看看