在开发过程中,遇到一个上传文件时的错误,特地在此记录一下。
相关代码:
- /*
- * 图片上传
- * */
- public static void sendMultipart(String urlAddress, String parms) {
- //这里根据需求传,不需要可以注释掉
- HiLog.info(TAG,"参数:"+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,"错误:"+e.getLocalizedMessage());
- HiLog.info(TAG,"错误:"+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);
- }
- }
- });
- }
复制代码错误信息如下:
/data/user/0/cn.jltf.neighbor/files/534.jpg: open failed: ENOENT (No such file)
错误显示没有这个文件,但该文件我尝试已经拿到页面上显示成功。大家有没有遇到本问题及解决方式是啥。
我们也正在检查,该问题会继续更新。