HarmonyOS 鸿蒙Next 选中图库里的照片上传,出现13400001

发布于 1周前 作者 zlyuanteng 来自 鸿蒙OS

HarmonyOS 鸿蒙Next 选中图库里的照片上传,出现13400001

import { openPhotoPicker } from ‘…/util/UtilPicker’;
import fs from ‘@ohos.file.fs’;
import { BusinessError, request } from ‘@kit.BasicServicesKit’;
import { common } from ‘@kit.AbilityKit’;

const context = getContext(this) as common.UIAbilityContext const cacheDir = context.cacheDir const fileType = ‘jpg’

@Entry @Component struct Test { @State imageUrl: string = ‘’

build() { Column() { Button(‘打开相册’) .onClick(async () => { let selectedImageUrl = await openPhotoPicker() if (selectedImageUrl) { this.imageUrl = selectedImageUrl console.log('imageUrl: ’ + this.imageUrl) } }) if (this.imageUrl) { Column() { Image(this.imageUrl) // 显示选中的图片 .width(50) .height(50) Button(‘上传图片’) .onClick(async () => { let fileName = Date.now() + ‘.’ + fileType let fullPath = ${cacheDir}/${fileName} let file = fs.openSync(this.imageUrl, fs.OpenMode.READ_ONLY) fs.copyFileSync(file.fd, fullPath)

          <span class="hljs-keyword">let</span> uploader: request.UploadConfig = {
            url: `http:<span class="hljs-comment">//localhost:8080/uploadAvatar`,</span>
            header: { <span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'multipart/form-data'</span> },
            method: <span class="hljs-string">'POST'</span>,
            files: [{
              filename: fileName,
              type: fileType,
              name: <span class="hljs-string">'avatar'</span>,
              uri: `internal:<span class="hljs-comment">//cache/${fileName}`,</span>
            }],
            data: []
          }
          <span class="hljs-keyword">try</span> {
            request.uploadFile(context, uploader)
              .then((uploadTask: request.UploadTask) =&gt; {
                uploadTask.on(<span class="hljs-string">'complete'</span>, (taskStates: <span class="hljs-built_in">Array</span>&lt;request.TaskState&gt;) =&gt; {
                  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; taskStates.length; i++) {
                    console.info(`upload complete taskState: ${<span class="hljs-built_in">JSON</span>.stringify(taskStates[i])}`);
                  }
                });
              })
              .catch((err: BusinessError) =&gt; {
                console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
              })
          } <span class="hljs-keyword">catch</span> (error) {
            <span class="hljs-keyword">let</span> err: BusinessError = error as BusinessError;
            console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
          }
        })
    }
    .width(<span class="hljs-string">'100%'</span>)
  }
}
.width(<span class="hljs-string">'100%'</span>)
.height(<span class="hljs-string">'100%'</span>)

} }<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

12-08 22:47:01.081   7283-7304     C01c50/Requestkit               com.examp…riefchat  E     [requestserviceproxy.cpp Create 77] End send create request, failed: 13400001
12-08 22:47:01.081   7283-7304     C01c50/Requestkit               com.examp…riefchat  E     [requestmanagerimpl.cpp Create 74] Request create, seq: 0, failed: 13400001
12-08 22:47:01.081   7283-7304     C01c50/Requestkit               com.examp…riefchat  E     [js_task.cpp CreateExec 202] End create task in JsTask CreateExec, seq: 0, failed: 13400001
12-08 22:47:01.081   7283-7283     C01c50/Requestkit               com.examp…riefchat  E     [js_task.cpp operator() 157] End task create in AsyncCall output, seq: 0, failed:13400001
12-08 22:47:01.081   7283-7283     C01c50/Requestkit               com.examp…riefchat  E     [napi_utils.cpp operator() 633] errorCode: 13400001, errInfo:
12-08 22:47:01.082   7283-7283     A03d00/JSAPP                    com.examp…riefchat  E     Invoke uploadFile failed, code is 13400001, message is  file operation error   <button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

出现这个错误,请问该如何解决,谢谢

1 回复

针对您提到的HarmonyOS 鸿蒙Next系统中在选中图库照片进行上传时遇到的错误代码“13400001”,这个问题可能由多种因素引起,包括但不限于系统bug、应用兼容性问题、权限设置不当或存储访问异常等。

首先,请确保您的鸿蒙系统已经更新到最新版本,因为系统更新通常会修复已知的错误和漏洞。同时,检查上传照片的应用是否也是最新版本,或者尝试使用其他应用进行上传操作,以排除应用本身的问题。

其次,检查您的应用权限设置,确保应用有权访问您的照片库。可以在设置中的“应用和服务”或“权限管理”里找到相关设置,并确保为应用开启了必要的权限。

此外,尝试重启设备,有时候简单的重启可以解决一些临时的系统问题。

如果以上步骤均未能解决问题,可能涉及到更复杂的系统或应用层面的问题。此时,建议您直接联系官网客服获取专业的技术支持。官网地址是:https://www.itying.com/category-93-b0.html ,他们会根据具体情况提供更详细的解决方案。

回到顶部