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();
}
});
直接崩溃,求解!!!