request.uploadFile报错13400001,file operation error ,后端服务也没收到接口请求
// 上传图片
let uploadTask: request.UploadTask;
let uploadConfig: request.UploadConfig = {
url: this.uploadUrl,//接口已测试用postman正常上传图片
header: { 'Accept': '*/*',"Content-Type": 'multipart/form-data','Authorization':AppStorage.get('token') },
method: http.RequestMethod.POST,
files: [{
filename: '1730648375163_566',
type: 'png',
name: 'file',
uri: `internal://cache/1730648375163_566.png`
//在Device File Browser有/data/app/el2/base/haps/entry/cache/1730648375163_566.png,当调用request.uploadFile时图片权限从-rw-rw-r--变成-rw-r--r--
}],
data: [],
};
try {
request.uploadFile(context, uploadConfig).then((data) => {
uploadTask = data;
uploadTask.on("progress", (size, tot) => {
this.msgHistory += `上传进度:${size}/${tot}\r\n`;
});
uploadTask.on("complete", () => {
this.msgHistory += "上传完成\r\n";
});
}).catch((e:BusinessError) => {
this.msgHistory += "请求失败:" + e.message + "\r\n";
});
} catch (err) {
this.msgHistory += 'err.code : ' + err.code + ', err.message : ' + err.message;
}