2 gowcage gowcage 于 2016.09.22 20:55 提问

retrofit2 上传文件直接崩溃,求解!!!

Bitmap bitmap = ((BitmapDrawable) iv_head_sculpture.getBackground()).getBitmap();
saveBitmap2file(bitmap, "headImg.png");
File file = new File(Environment.getExternalStorageDirectory() + "headImg.png");
RequestBody headImg =
RequestBody.create(MediaType.parse("multipart/form-data"), file);
call = apiService.uploadHeadImg(headImg);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
DataResult result = response.body();
Log.i("gowcage-test", result.toString());
Toast.makeText(getApplicationContext(),
"图片上传成功", Toast.LENGTH_LONG).show();
}

                @Override
                public void onFailure(Call<DataResult> call, Throwable t) {
                    Toast.makeText(getApplicationContext(),
                            "图片上传失败", Toast.LENGTH_LONG).show();
                }
            });
                            直接崩溃,求解!!!

1个回答

devmiao
devmiao   Ds   Rxr 2016.09.23 00:38
已采纳
Csdn user default icon
上传中...
上传图片
插入图片