使用ionic framework在iOS上无法从视频URI转换为blob

zte4gxcn  于 2023-03-16  发布在  Ionic
关注(0)|答案(1)|浏览(168)

我使用下面的代码将视频文件转换为iOS的blob。

Takevideo()
      {
          const options: CameraOptions = {
            sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, 
            destinationType: this.camera.DestinationType.DATA_URL,
            mediaType: this.camera.MediaType.VIDEO      
          }
            this.camera.getPicture(options).then(async (videoUrl) => {
              debugger;
              this.selectvideopath=null;
              var filename = videoUrl.substr(videoUrl.lastIndexOf('/') + 1);
              var dirpath = videoUrl.substr(0, videoUrl.lastIndexOf('/') + 1);
    
              dirpath = dirpath.includes("file://") ? dirpath : "file://" + dirpath;
              try {
                var dirUrl = await this.file.resolveDirectoryUrl(dirpath);
                var retrievedFile = await this.file.getFile(dirUrl, filename, {});
                this.makeFileIntoBlob(retrievedFile.nativeURL);
              } catch(err) {
                return this.ionLoader.showAlert("Something went wrong.");
              }
             
             }, (err) => {
              // Handle error
             });
      }
    
      makeFileIntoBlob(_imagePath) {
        return new Promise((resolve, reject) => {
          console.log("makefileintoblob", +_imagePath);
          let fileName = "";
          this.file
            .resolveLocalFilesystemUrl(_imagePath)
            .then(fileEntry => {
              let { name, nativeURL } = fileEntry;
    
              let path = nativeURL.substring(0, nativeURL.lastIndexOf("/"));
              console.log("path", path);
              console.log("fileName", name);
    
              fileName = name;
    
              var buffer=this.file.readAsArrayBuffer(path, name);
              console.log("makefileintoblob buffer: " +buffer);
              this.Videodatas.push({vdodata:buffer});
              return this.file.readAsArrayBuffer(path, name);
            })
            .then(buffer => {
              this.ionLoader.showAlert('2:'+buffer);
              console.log("makefileintoblob buffernew: " +buffer);
              let imgBlob = new Blob([buffer], {
                type: "video/MOV"
              });
              console.log(imgBlob.type, imgBlob.size);
              resolve({
                fileName,
                imgBlob
              });
            })
            .catch(e => reject(e));
        });
      }

但是下面的代码块没有执行。

.then(buffer => {
              this.ionLoader.showAlert('2:'+buffer);
              console.log("makefileintoblob buffernew: " +buffer);
              let imgBlob = new Blob([buffer], {
                type: "video/MOV"
              });
              console.log(imgBlob.type, imgBlob.size);
              resolve({
                fileName,
                imgBlob
              });

我已经安装了软件包:npm安装--保存@ionic-native/文件传输npm安装cordova插件文件传输npm安装cordova插件文件
有人能帮我解决这个问题吗?

vaj7vani

vaj7vani1#

我无法将视频转换为iOS的blob。所以我通过API将视频发送到服务器。找到下面的链接:
使用ionic框架和web API上传文件到服务器

相关问题