HarmonyOS应用开发-图片文件上传错误交流

鸿蒙时代
发布于 2022-3-25 10:19
2143浏览
0收藏

在开发过程中,遇到一个上传文件时的错误,特地在此记录一下。
相关代码:

/*
* 图片上传
* */
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);
            }
        }
    });
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.

错误信息如下:
/data/user/0/cn.jltf.neighbor/files/534.jpg: open failed: ENOENT (No such file)

错误显示没有这个文件,但该文件我尝试已经拿到页面上显示成功。大家有没有遇到本问题及解决方式是啥。
我们也正在检查,该问题会继续更新。

分类
标签
HarmonyOS应用开发-图片文件上传错误交流.docx 17.21K 31次下载
收藏
回复
举报


回复
    相关推荐