欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp在開發(fā)app時(shí)上傳文件時(shí)的問題記錄

 更新時(shí)間:2024年09月13日 09:20:43   作者:BUG創(chuàng)建者  
在開發(fā)uniapp應(yīng)用時(shí),可能會(huì)遇到文件上傳功能在iOS和部分Android手機(jī)上不兼容的問題,經(jīng)過對(duì)比分析,發(fā)現(xiàn)問題可能出在文件的路徑上,通過使用uni.saveFile方法保存文件后,再上傳可以解決問題,這篇文章詳細(xì)介紹了解決方案,并引導(dǎo)讀者參考更多相關(guān)內(nèi)容

手機(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)文章

最新評(píng)論