uniapp在開發(fā)app時上傳文件時的問題記錄
手機(jī)拍照然后上傳沒問題 但是在相冊中選擇的照片上傳 ios手機(jī)不行 安卓一部分手機(jī)也點擊沒反應(yīng)
最后對比了下參數(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, //默認(rèn)9
sizeType: ["compressed"], //可以指定是原圖還是壓縮圖,默認(rèn)二者都
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)文章
JavaScript實現(xiàn)像雪花一樣的Hexaflake分形
這篇文章主要介紹了JavaScript實現(xiàn)像雪花一樣的Hexaflake分形,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
e.target與e.currentTarget對象的使用區(qū)別詳解
這篇文章主要為大家介紹了e.target與e.currentTarget的使用區(qū)別示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
javascript實現(xiàn)div的顯示和隱藏的小例子
這篇文章介紹了在JS中實現(xiàn)DIV顯示和隱藏的實例,需要的朋友可以參考一下2013-06-06
前端JavaScript實現(xiàn)添加防刪除水印的方案
最近在做一個 AI 多模態(tài)項目,有個需求是在對話記錄下載預(yù)覽彈窗中加水印,還要要防止用戶去掉我們的水印,所以本文給大家介紹了前端添加防刪除水印的技術(shù)實現(xiàn),需要的朋友可以參考下2025-10-10
Vuejs通過拖動改變元素寬度實現(xiàn)自適應(yīng)
這篇文章主要介紹了Vuejs通過拖動改變元素寬度實現(xiàn)自適應(yīng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-09-09
javascript中style.left和offsetLeft的用法說明
本篇文章主要是對javascript中style.left和offsetLeft的用法進(jìn)行了說明介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-03-03

