Android 实现上传头像(仿京东项目)

File file = new File(getFilesDir().getAbsolutePath());

if (!file.exists()) {

    file.mkdirs();

}

File file1 = new File(file, "photo.png");
FileOutputStream fileOutputStream;
try {
    fileOutputStream = new FileOutputStream(file1);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
    fileOutputStream.flush();
    fileOutputStream.close();
} catch (Exception e) {
    e.printStackTrace();
}

RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file1);

MultipartBody.Part part = MultipartBody.Part.createFormData("file", file1.getName(), requestBody);

猜你喜欢

转载自blog.csdn.net/as89751/article/details/81098810