在開(kāi)發(fā)過(guò)程中,遇到一個(gè)上傳文件時(shí)的錯(cuò)誤,特地在此記錄一下。
相關(guān)代碼:
/*
* 圖片上傳
* */
public static void sendMultipart(String urlAddress, String parms) {
//這里根據(jù)需求傳,不需要可以注釋掉
HiLog.info(TAG,"參數(shù):"+parms);
HiLog.info(TAG,"鏈接:"+urlAddress);
MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
RequestBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("parms", parms)
.addFormDataPart("image", "wangshu.jpg",
RequestBody.create(MEDIA_TYPE_PNG, new File("/data/user/0/cn.jltf.neighbor/files/534.jpg")))
.build();
Request request = new Request.Builder()
.header("Authorization", "Client-ID " + "...")
.url(urlAddress)
.post(body)
.build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
HiLog.info(TAG,"錯(cuò)誤:"+e.getLocalizedMessage());
HiLog.info(TAG,"錯(cuò)誤:"+e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
String res = response.body().string();
HiLog.info(TAG, "onResponse: " + res);
}
}
});
}
錯(cuò)誤信息如下:
/data/user/0/cn.jltf.neighbor/files/534.jpg: open failed: ENOENT (No such file)
錯(cuò)誤顯示沒(méi)有這個(gè)文件,但該文件我嘗試已經(jīng)拿到頁(yè)面上顯示成功。大家有沒(méi)有遇到本問(wèn)題及解決方式是啥。
我們也正在檢查,該問(wèn)題會(huì)繼續(xù)更新
審核編輯:符乾江
-
應(yīng)用開(kāi)發(fā)
+關(guān)注
關(guān)注
0文章
58瀏覽量
9361 -
HarmonyOS
+關(guān)注
關(guān)注
79文章
1975瀏覽量
30202
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論