上传Resource图片
try {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.biaoqian);
FileOutputStream outputStream = openFileOutput("bitmap.jpg", MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
// bitmap2File(bitmap, new File(getFilesDir(), "bitmap.jpg"));
// file = saveFile(bitmap, "bitmap.jpg");
} catch (Exception e) {
e.printStackTrace();
}
OkHttpUtils
.post()
.url("http://123.56.41.81:8080/imgtest/img.do?code=0")
.addFile("bitmap", "bitmap.jpg", new File(getFilesDir(), "bitmap.jpg"))
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
Log.e("上传图片测试", e + "");
}
@Override
public void onResponse(String response, int id) {
Log.e("上传图片测试", response);
}
}); |