android上传视频

MultipartBody.Builder mbody = new MultipartBody.Builder().setType(MultipartBody.FORM);
                Log.e("cxy",selectList.get(0).getPath());
                File file = new File(selectList.get(0).getPath());
                MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), RequestBody.create(MediaType.parse("multipart/form-data"), file));
                mbody.addPart(body);
                //构建请求体
                RequestBody requestBody = mbody.build();
                OkHttpClient.initPost("http://192.168.1.17:8080/files", requestBody).enqueue(new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        Log.e("cxy","GG:"+e.getMessage());
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        Log.e("cxy",response.body().string());
                    }
                });

 

你可能感兴趣的:(android)