在iphone中无法调用firebase.storage()

时间:2017-12-13 05:55:25

标签: angular firebase ionic-framework angularfire firebase-storage

我正在开发一种带离子的混合应用程序。 firebase.storage()不工作...... 请帮帮我..

离子信息 cli包:(C:\ Program Files(x86)\ nodejs \ node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

全球套餐:

cordova (Cordova CLI) : 7.1.0

本地包裹:

@ionic/app-scripts : 2.1.3
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.6.0

系统:

Node : v6.11.0
npm  : 3.10.10
OS   : Windows 10

我的Package.json  :https://drive.google.com/open?id=1n9a51UJ3wTGIim3WVbIzhW4_ftYfNJN4

我开发了一个用户选择的文件作为图像上传到firebase存储。

当" uploadVerify()"是从" login.html"文件, 用户选择的文件更改为blob。

之后,它通过" uploadPicture()"存储在存储器中。功能。 它适用于本地(浏览器中的离子服务), 但iPhone似乎无法调用firebase.storage()部分。

如果有办法,请求帮助。感谢。



import { Component, Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { AlertController, LoadingController } from 'ionic-angular';
import { NavController, MenuController, NavParams, ModalController } from 'ionic-angular';
import { CoolLocalStorage } from 'angular2-cool-storage';
import { SearchPage } from '../search/search';
import { FilterPage } from '../filter/filter';
import { AutoCompletePage } from '../autocomplete/autocomplete';
import { UtilProvider } from '../../providers/util/utils';
import { Ng2ImgToolsService } from 'ng2-img-tools';
import 'rxjs/add/operator/map';
import { AngularFireAuth } from 'angularfire2/auth'
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import * as firebase from 'firebase/app';
import 'firebase/storage';

@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})

export class LoginPage {
  storage: CoolLocalStorage; 

  isEnabled = true; isReadonly = true;
  imgFile1; imgName;
  verificationImageURL;

  constructor(public nav: NavController, public menu: MenuController, private modalCtrl: ModalController,
	  private navParams: NavParams, public alertCtrl: AlertController, public util: UtilProvider, private ng2ImgToolsService: Ng2ImgToolsService,
    storage: CoolLocalStorage, public http: Http, public loadingCtrl: LoadingController, public afAuth: AngularFireAuth,
    private afDB: AngularFireDatabase) {
	  this.storage = storage;
    
    this.menu.swipeEnable(false);
  }
  uploadVerify(event){
      if(event.target.files && event.target.files[0]){
        let fileList: FileList = event.target.files;
        let file: File = fileList[0];
        if( !file.type.match(/image.*/)){
            this.util.doAlert("error","not image","ok");
            event.target.result = "";
        }else{
            this.ng2ImgToolsService.resize( [file], 400, 400).subscribe(
              result =>{
                this.util.doAlert("imageResize", result,"확인");
                /*
                let loading = this.loadingCtrl.create({
                  content: 'upload...'
                });
                loading.present();
                */
                this.imgFile1 = new File( [result], result.name);
                this.imgName = Date.parse(new Date().toISOString()).toString();
                this.uploadPicture(this.imgFile1, this.imgName).then(imageUrl =>{
                    if( imageUrl ){
                      this.util.doAlert("uploadedFirebase", imageUrl,"확인");
                      //loading.dismiss();
                      this.verificationImageURL = imageUrl;
                    }else{
                    }
                });
              },
              Error =>{
                console.log('img1 Compression error');
            });
        }
      }
  }
  uploadPicture(file, imageName){
    let email = this.email;
    let promise = new Promise((res, rej) => {
      let fileName = imageName + '.jpg';
      let pictureRef = firebase.storage().ref('/userVerifications/'+email+'/'+fileName);
      let metadata: firebase.storage.UploadMetadata = {
        contentType: 'image/jpeg',
      };
      let uploadTask = pictureRef.put(file, metadata);
      uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, (snapshot) =>{

      },(error) => {
          rej(error);
      },() => {
          var downloadURL = uploadTask.snapshot.downloadURL;
          res(downloadURL);
      });
    });
    return promise;
  }
  }




0 个答案:

没有答案