首页 > Web开发 > 详细

使用HttpUtils 上传视频文件

时间:2016-08-19 17:27:14      阅读:305      评论:0      收藏:0      [点我收藏+]

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

使用HttpUtils 上传视频文件

原文:http://www.cnblogs.com/changyiqiang/p/5788383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!