在6.0 7.0 上传图片没问题。在10.0下就一直报错
Method threw 'java.io.FileNotFoundException' exception
我的代码
public String uploadImage(String url, String imagePath) throws IOException, JSONException {
OkHttpClient okHttpClient = new OkHttpClient();
// Log.d("imagePath", imagePath);
File file = new File(imagePath);
RequestBody image = RequestBody.create(MediaType.parse("image/png"), file);
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("path", "taskPlanApp")
.addFormDataPart("attach", imagePath, image)
.addFormDataPart("thumbnailWidth", "80")
.addFormDataPart("thumbnailHeigth", "80")
.build();
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = new JSONObject(response.body().string());
Integer error = jsonObject.getInt("error");
String msg = jsonObject.getString("message");
if (error == 0) {
imgLoadUrl = jsonObject.getString("url");
} else {
Toast.makeText(ConfirmOldManInfo.this, msg, Toast.LENGTH_SHORT).show();
}
return jsonObject.optString("image");
}