ionic 4:我想使用Flow.js上传视频文件,但出现错误

时间:2018-10-23 11:26:00

标签: file-upload ionic4 flow-js

我可以从camera.getPicture()拾取视频文件,
但我无法使用this.upload()[Flow.js api]上传文件(fileUri)。 我尝试使用Videojs将视频拾起并将文件(fileUri)发送到服务器,
但什么也没发生。

我的Ionic Hybrid Android App logcat如下:

10-23 14:48:17.291 22292-22292/io.ionic.starter D/CordovaActivity: Incoming Result. Request code = 18. 
10-23 14:48:17.291 22292-22292/io.ionic.starter D/CordovaInterfaceImpl: Sending activity result to plugin. 
10-23 14:48:17.291 22292-22292/io.ionic.starter D/CordovaActivity: Started the activity.  
10-23 14:48:17.291 22292-22292/io.ionic.starter D/CordovaActivity: Resumed the activity.  
10-23 14:48:17.326 22292-22292/io.ionic.starter D/dalvikvm: GC_FOR_ALLOC freed 1189K, 12% free 13758K/15604K, paused 32ms, total 33ms. 
10-23 14:48:17.351 22292-22490/io.ionic.starter D/CameraLauncher: File locaton is: /storage/emulated/0/DCIM/Camera/20181008_100932.mp4. 
10-23 14:48:17.441 22292-22494/io.ionic.starter D/[FilePath plugin]:: URI: /storage/emulated/0/DCIM/Camera/20181008_100932.mp4. 
10-23 14:48:17.446 22292-22494/io.ionic.starter D/[FilePath plugin]:: File - Authority: null, Fragment: null, Port: -1, Query: null, Scheme: null, Host: null, Segments: [storage, emulated, 0, DCIM, Camera, 20181008_100932.mp4]. 
10-23 14:48:17.456 22292-22292/io.ionic.starter W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection. 

这是我的ionic4代码:

    public start() {
        let options: CameraOptions = {
          quality: 50,
          destinationType: this.camera.DestinationType.FILE_URI,
          sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
          allowEdit: false,
          mediaType: this.camera.MediaType.VIDEO,
          // popoverOptions: CameraPopoverOptions,
          saveToPhotoAlbum: false};

        this.camera.getPicture(options)
          .then((fileUri)=> {



            this.path.resolveNativePath(fileUri)
                   .then((filePath)=>{
                     this.auth.presentAlert(filePath)
                     this.upload(filePath);                
                    },(err) => {
                      this.auth.presentAlert(err) ;
                    });


          }, 
          (err) => {
            this.auth.presentAlert(err.message) ;
          }) ;     
      }

      public upload(fileUri:string){

        var file: File = new File(null, fileUri, {})
        this.auth.presentAlert(file.name) ;

        const flow = new Flow({
          target: this.auth.apiHostUrl + '/upload',
          chunkSize: 300000,
          forceChunkSize: true,
          simultaneousUploads: 7,
          permanentErrors: [415, 500, 501]
        });

        flow.on('fileSuccess', (file, message) => {
          this.auth.presentAlert("upload success !!!")
          this.auth.hideLoading();
        });

        flow.on('fileError', (file, message) => {
          this.auth.presentAlert(message) ;
          this.auth.hideLoading();
        });

        flow.on('fileProgress', file => {
          if (flow.progress()) {
            this.loadProgress = Math.floor(flow.progress() * 100);
          }
        });

        flow.addFile(file) ;
        flow.upload() ;
        this.auth.showLoading() ;    
      }
    }

0 个答案:

没有答案