uniapp在開發(fā)app時上傳文件時的問題記錄
手機拍照然后上傳沒問題 但是在相冊中選擇的照片上傳 ios手機不行 安卓一部分手機也點擊沒反應
最后對比了下參數(shù) 發(fā)現(xiàn)路徑有所不同
使用uni.saveFile保存路徑好在重新上傳
saveFileSync(tempFilePath){
return new Promise((resolve, reject) => {
uni.saveFile({
tempFilePath,
success: function (file) {
resolve(file.savedFilePath)
},
fail: function (error) {
reject(error)
}
})
})
}, uni.chooseImage({
count: 1, //默認9
sizeType: ["compressed"], //可以指定是原圖還是壓縮圖,默認二者都
sourceType: ['camera','album'],
success: async function(result) {
let ewm = result.tempFiles[0]
const path = await that.saveFileSync(ewm.path)
if (result.errMsg === "chooseImage:ok") {
result.tempFiles[0].path=path
// that.upload(path);
that.upload(result.tempFiles[0]);
} else {
uni.showToast({
title: "圖片上傳失敗",
icon: "none",
});
}
},
fail(err) {
uni.showToast({
title: "取消上傳",
icon: "none",
});
},
});Upload(event) {
const token = this.getToken();
// const url = this.getuploadUrl();
const imgList = [];
uni.showLoading({
title: "上傳中...",
mask: true,
});
try {
const [err, res] = await uni.uploadFile({
url: `${HOST}/resource/file/upload`,
filePath: event.path,
name: "file",
header: {
Authorization: token,
},
});
if (res && (res.statusCode === 200)) {
const result = JSON.parse(res.data);
if (result.code == 200) {
let res1 = JSON.parse(res.data);
res1.data.uuid = res1.data.id;
res1.data.paramskey = event.name;
imgList.push(res1.data);
const list = [...this.list, ...imgList];
this.$emit("value", list);
this.$emit("change", list);
this.$emit("upload", imgList);
} else {
wx.showToast({
icon: "none",
title: result.msg,
});
}
} else {
wx.showToast({
icon: "error",
title: "上傳失敗",
});
}
} catch (error) {
console.log(error)
}
uni.hideLoading();
this.$emit("upload", imgList);
},到此這篇關(guān)于uniapp在開發(fā)app時上傳文件時的問題的文章就介紹到這了,更多相關(guān)uniapp上傳文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于MooTools的很有創(chuàng)意的滾動條時鐘動畫
一款很有創(chuàng)意的時鐘js動畫.是利用系統(tǒng)滾動條來構(gòu)成一個 時:分:秒 的盤. 再利用滾動條的長度變化做過渡動畫.2010-11-11
微信小程序navigator跳轉(zhuǎn)及參數(shù)傳遞的方法
這篇文章主要介紹了微信小程序navigator跳轉(zhuǎn)及參數(shù)傳遞,在navigator中添加需要跳轉(zhuǎn)的路徑,如果需要帶參,則在路徑后面添加所要傳遞的參數(shù)以及值,需要的朋友可以參考下2023-11-11
JavaScript函數(shù)式編程(Functional Programming)純函數(shù)用法分析
這篇文章主要介紹了JavaScript函數(shù)式編程(Functional Programming)純函數(shù)用法,結(jié)合實例形式分析了javascript函數(shù)式編程中純函數(shù)的函數(shù)依賴、所指透明等概念相關(guān)原理及使用技巧,需要的朋友可以參考下2019-05-05
JavaScript css3實現(xiàn)簡單視頻彈幕功能
這篇文章主要為大家詳細介紹了JavaScript css3實現(xiàn)簡單視頻彈幕功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-07-07

