HarmonyOS使用axios进行相册图片上传操作失败
使用axios进行图片上传失败 报错提示 Error: empty error message, 不知道是什么原因导致的。代码:
const photoViewPicker = new picker.PhotoViewPicker();
let ctx = getContext(this)
let photoSelectResult = await photoViewPicker.select(photoSelectOptions)
uris = photoSelectResult.photoUris;
for (let index = 0; index < uris.length; index++) {
const element = uris[index];
console.error('====>uri is:' + element + ', start read file')
fs.open(element, (err, file) => {
if (err) {
console.error("====>file open failed with error message: " + err.message + ", error code: " +
err.code);
} else {
let filepath = `${ctx.cacheDir}/${file.name}`;
console.error('====>filepath is:' + filepath + ', start copy file')
fs.copyFile(file.fd, filepath, () => {
// 上传的uri
let uri = fileUri.getUriFromPath(filepath)
console.error("文件uri路径:" + uri)
let realUri = `internal://cache/${file.name}`;
console.error("real uri:" + realUri)
// 执行上传
let request: AxiosRequestConfig<FormData> = {
url: config.subUrl,
headers: {
'Content-Type': 'multipart/form-data'
},
context: getContext(),
method: "post",
params: params,
data: formData
}
let resp: AxiosResponse<HttpResponseModel> =
await axios.request<HttpResponseModel, AxiosResponse<HttpResponseModel>, FormData>(request)
});
}
})
}
console.error('photoViewPicker.select to file succeed and uris are:' + uris);
} catch (err) {
console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
}
错误提示:
E [ecmascript] Pending exception before ToObject called in line:239, exception details as follows:
Error: empty error message
at upload (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/upload.js:140:1)
at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/index.js:31:1)
at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/index.js:26:1)
at dispatchRequest (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/core/dispatchRequest.js:51:1)
at request (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/core/Axios.js:170:1)
at wrap (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/helpers/bind.js:5:1)
at apiRequest (entry/src/main/ets/core/network/service.ets:90:15)
[ecmascript] Pending exception before Has called in line:1891, exception details as follows:
Error: empty error message
at upload (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/upload.js:140:1)
at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/index.js:31:1)
at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/index.js:26:1)
at dispatchRequest (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/core/dispatchRequest.js:51:1)
at request (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/core/Axios.js:170:1)
at wrap (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/helpers/bind.js:5:1)
at apiRequest (entry/src/main/ets/core/network/service.ets:90:15)
[ecmascript] Pending exception before IsMixedDebugEnabled called in line:3573, exception details as follows:
Error: empty error message
at upload (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/upload.js:140:1)
at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/index.js:31:1)
at anonymous (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/adapters/ohos/index.js:26:1)
at dispatchRequest (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/core/dispatchRequest.js:51:1)
at request (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/core/Axios.js:170:1)
at wrap (oh_modules/.ohpm/@ohos+axios@2.2.0/oh_modules/@ohos/axios/src/main/ets/components/lib/helpers/bind.js:5:1)
at apiRequest (entry/src/main/ets/core/network/service.ets:90:15)
[default] ConstructorOptimize:2520 occur exception need return
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
使用axios上传图片时候错误
98浏览 • 1回复 待解决
rcp上传的时候如果是相册里面图片路径怎么上传,直接上传uri会失败
329浏览 • 1回复 待解决
HarmonyOS如何上传图片到模拟器相册
802浏览 • 1回复 待解决
拉起相册选择图片页面失败
1880浏览 • 1回复 待解决
HarmonyOS 如何拉起系统相册,选择图片进行上传云端,能否提供个demo或者文档链接参考?
166浏览 • 1回复 待解决
HarmonyOS版Axios走文件上传请求时,如果ssl握手失败,没有回调
459浏览 • 1回复 待解决
HarmonyOS调用相册管理api,创建并保存图片至相册失败,查看图片是空白
346浏览 • 1回复 待解决
通过web上传图片并进行预览
905浏览 • 1回复 待解决
基于PhotoViewPicker对图片进行操作
760浏览 • 1回复 待解决
如何对相册图片进行编辑裁剪
1736浏览 • 1回复 待解决
使用FilePick上传uri失败,报错201
1696浏览 • 1回复 待解决
从相册选择图片上传到端上,图片较大需要先压缩在上传到端上,需要图片压缩工具
1677浏览 • 1回复 待解决
HarmonyOS 测试命令行相关使用
432浏览 • 1回复 待解决
从本机获取图片进行上传到spring后端
2355浏览 • 1回复 待解决
图片剪切,HarmonyOS提供图片剪切能力,并对截取后的资源进行操作。
1054浏览 • 1回复 待解决
HarmonyOS图片上传相关问题
410浏览 • 1回复 待解决
HarmonyOS如何向模拟器相册添加一些图片?如何实现通过接口把从相册选的图片上传到服务器?
416浏览 • 1回复 待解决
如何使用onShowFileSelector()函数拉起图库上传图片
2154浏览 • 1回复 待解决
HarmonyOS图片保存相册问题
373浏览 • 1回复 待解决
HarmonyOS web上传文件和图片
200浏览 • 1回复 待解决
HarmonyOS如何实现图片的上传
398浏览 • 1回复 待解决
HarmonyOS中使用axios进行网络请求配合async的时候会使用多线程吗?
83浏览 • 0回复 待解决
#鸿蒙通关秘籍#使用axios进行HTTP GET和POST请求
25浏览 • 1回复 待解决
HarmonyOS 保存图片到相册问题
223浏览 • 1回复 待解决
HarmonyOS Web 图片上传功能失效
166浏览 • 1回复 待解决
在请求中未设置请求头,headers: { ‘Content-Type’: ‘multipart/form-data’ },请参考gitee的代码实例:https://gitee.com/openharmony-sig/ohos_axios#%E5%BD%93%E4%B8%8A%E4%BC%A0%E7%9A%84%E5%86%85%E5%AE%B9%E4%B8%BAarraybuffer%E6%97%B6%E7%94%A8%E6%B3%95%E5%A6%82%E4%B8%8B
formData里有其他字段会触发empty error message问题,只包含file这一个字段可以请求成功: