uniapp在開發(fā)app時(shí)上傳文件時(shí)的問題記錄
手機(jī)拍照然后上傳沒問題 但是在相冊(cè)中選擇的照片上傳 ios手機(jī)不行 安卓一部分手機(jī)也點(diǎn)擊沒反應(yīng)
最后對(duì)比了下參數(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時(shí)上傳文件時(shí)的問題的文章就介紹到這了,更多相關(guān)uniapp上傳文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于MooTools的很有創(chuàng)意的滾動(dòng)條時(shí)鐘動(dòng)畫
一款很有創(chuàng)意的時(shí)鐘js動(dòng)畫.是利用系統(tǒng)滾動(dòng)條來構(gòu)成一個(gè) 時(shí):分:秒 的盤. 再利用滾動(dòng)條的長(zhǎng)度變化做過渡動(dòng)畫.2010-11-11微信小程序navigator跳轉(zhuǎn)及參數(shù)傳遞的方法
這篇文章主要介紹了微信小程序navigator跳轉(zhuǎn)及參數(shù)傳遞,在navigator中添加需要跳轉(zhuǎn)的路徑,如果需要帶參,則在路徑后面添加所要傳遞的參數(shù)以及值,需要的朋友可以參考下2023-11-11JavaScript函數(shù)式編程(Functional Programming)純函數(shù)用法分析
這篇文章主要介紹了JavaScript函數(shù)式編程(Functional Programming)純函數(shù)用法,結(jié)合實(shí)例形式分析了javascript函數(shù)式編程中純函數(shù)的函數(shù)依賴、所指透明等概念相關(guān)原理及使用技巧,需要的朋友可以參考下2019-05-05JavaScript css3實(shí)現(xiàn)簡(jiǎn)單視頻彈幕功能
這篇文章主要為大家詳細(xì)介紹了JavaScript css3實(shí)現(xiàn)簡(jiǎn)單視頻彈幕功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07