Ionic 3-如何将视频文件从库上传到Firebase存储设备

时间:2018-06-28 16:27:49

标签: firebase ionic-framework ionic3 angularfire2 ionic-native

我找到了许多用于将图像和音频从Ionic 3上传到Firebase存储的解决方案,但没有找到一种将视频文件从图库上传到Firebase存储的解决方案。我一直在寻找“相机”,“文件”,“文件路径”,“插件”等,但是似乎找不到找到将mp4文件从我的画廊上传到存储设备的有效解决方案。

我最初尝试过此方法(但没有用):

uploadpage.ts

  async selectVideo(){
    const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      // encodingType: this.camera.EncodingType,
      mediaType: this.camera.MediaType.ALLMEDIA
    }
    let result = await this.camera.getPicture(options);
    result.then((uri) => {
      this.spinner.load();
  this.selectedVideo = uri;
 }, (err) => {
  // Handle error
  this.helper.presentToast(err.message);
 });
  }




  //Upload video
 uploadVideo(){
    if(this.selectedVideo){
      this.spinner.load();
    //upload task 
     let upload= this.api.uploadVideo(this.selectedVideo)
     upload.then().then(res => {
       let otherData={title:this.title,category:this.type, thumbnail:this.thumbnail}
       this.api.storeInfoToDatabase(res.metadata, otherData).then(()=>{
       this.spinner.dismiss();
       })
     })

    }

  }

api.ts

uploadVideo(data): AngularFireUploadTask{
  let newName = `${new Date().getTime()}.mp4`;
  let footballerId = JSON.parse(localStorage.getItem('data')).uid;
   return this.afStorage.ref(`videos/${newName}`).putString(data);
}
storeInfoToDatabase(metaInfo, data){
  let toSave={
    created:metaInfo.timeCreated,
    url: metaInfo.downloadURLs[0],
    fullPath: metaInfo.fullPath,
    contentType: metaInfo.contentType,
    footballerId:'',
    title: data.title || '',
    type:data.type || '',
    thumbnail: data.thumbnail || '',
  }
  toSave.footballerId = JSON.parse(localStorage.getItem('data')).uid;
  return this.addVideo(toSave);
}

0 个答案:

没有答案