调用 request.uploadFile 的时候报错
Error: the parameters check fails this is fail path@431a5ed1
代码如下:
uploadFile() {
// 上传任务配置项
let header = new Map<Object, string>();
header.set('partner_id', this.partnerId);
header.set('user_number', this.userNumber);
let files: Array<request.File> = [
{ filename: 'wenzai_logs', name: 'wenzai_logs', uri: 'internal:/data/storage/el2/base/haps/entry/files/wenzai_logs.zip' , type: 'zip' }
]
let requestData: Array<request.RequestData> = [{ name: 'name', value: 'value' }];
let uploadConfig: request.UploadConfig = {
url: API_HOST_WEB[this.deployType] + UP_LODE_LOG_FILE,
header: header,
method: 'POST',
files: files,
data: requestData
}
try {
request.uploadFile(context, uploadConfig)
.then((uploadTask: request.UploadTask) => {
uploadTask.on('complete', (taskStates: Array<request.TaskState>) => {
for (let i = 0; i < taskStates.length; i++) {
console.info(`upload complete taskState: ${JSON.stringify(taskStates[i])}`);
}
});
})
.catch((err: BusinessError) => {
console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
})
} catch (error) {
let err: BusinessError = error as BusinessError;
console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
}
}
请帮忙看下哪个地方写错了
根据文档当前能力如此,当前只支持上传cache目录下的文件, 非cache目录下上传下载解决方案: 将公共路径的文件(picker选择),拷贝至沙箱路径中,可完成上传。这边提供一个demo参考一下
Demo:
应用文件上传下载,可以参考最新更新的文档:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/app-file-upload-download-V5