處理 plus.io.resolveLocalFileSystemURL IOS上傳圖片兼容問題


處理 plus.io.resolveLocalFileSystemURL IOS上傳圖片兼容問題

  問題:plus.io.resolveLocalFileSystemURL ios 報錯 不允許讀

  處理方式:指定下視頻保存的路徑

{
    filename: "_doc/camera/",
    filter: "image",
    system: false
}

  代碼例子:

  相冊選擇:

plus.gallery.pick(
            function(filePath) {
              alert(filePath);
              plus.io.resolveLocalFileSystemURL(
                filePath,
                function(entry) {
                  entry.file(function(file) {
                    let reader = null;
                    reader = new plus.io.FileReader();
                    reader.onload = function(e) {};
                    reader.readAsDataURL(file);
                    reader.onloadend = function(e) {
                      let dataBase = e.target.result;
                      uploadImgBase64({
                        file: dataBase
                      })
                        .then(res => {
                          if (res.data.code === 200) {
                            _this.alertVal = "圖片上傳成功";
                            _this.showPluginAuto();
                          } else {
                            _this.alertVal = res.data.msg;
                            _this.showPluginAuto();
                          }
                        })
                        .catch(() => {
                          _this.alertVal = "圖片上傳失敗!";
                          _this.showPluginAuto();
                        });
                    };
                  });
                },
                function(e) {}
              );
            },
            function(e) {},
            {
              filename: "_doc/camera/",
              filter: "image",
              system: false
            }
          );

  拍照上傳:

let camera = plus.camera.getCamera();
          camera.captureImage(
            function(filePath) {
              alert(filePath);
              plus.io.resolveLocalFileSystemURL(
                filePath,
                function(entry) {
                  entry.file(function(file) {
                    let reader = null;
                    reader = new plus.io.FileReader();
                    reader.onload = function(e) {};
                    reader.readAsDataURL(file);
                    reader.onloadend = function(e) {
                      let dataBase = e.target.result;
                      uploadImgBase64({
                        file: dataBase
                      })
                        .then(res => {
                          if (res.data.code === 200) {
                            _this.alertVal = "圖片上傳成功";
                            _this.showPluginAuto();
                          } else {
                            _this.alertVal = res.data.msg;
                            _this.showPluginAuto();
                          }
                        })
                        .catch(() => {
                          _this.alertVal = "圖片上傳失敗!";
                          _this.showPluginAuto();
                        });
                    };
                  });
                },
                function(e) {}
              );
            },
            function(e) {},
            {
              filename: "_doc/camera/",
              index: 1
            }
          );

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM