使用angular将文件上传到firebase时如何处理firebase存储中的两个存储桶

Moh*_*agd 5 buckets firebase firebase-storage angular

在 app.module

AngularFireModule.initializeApp(environment.firebaseConfig)
Run Code Online (Sandbox Code Playgroud)

我有两个存储

firebaseConfig: {
    apiKey: 'AIzaSyBHsAxVgiuM0_xLd3BunTG6Yf9x1nynxoA',
    authDomain: 'careerograph-e9963.firebaseapp.com',
    databaseURL: 'https://careerograph-e9963.firebaseio.com',
    projectId: 'careerograph-e9963',
    storageBucket: 'careerograph-e9963.appspot.com',
    messagingSenderId: '669874223858'
  },
  firebaseExcelConfig: {
    apiKey: 'AIzaSyBHsAxVgiuM0_xLd3BunTG6Yf9x1nynxoA',
    authDomain: 'careerograph-e9963.firebaseapp.com',
    databaseURL: 'https://careerograph-e9963.firebaseio.com',
    projectId: 'careerograph-e9963',
    messagingSenderId: '669874223858',
    storageBucket: 'careerograph-excel',
  },
Run Code Online (Sandbox Code Playgroud)

在我注入构造函数私有存储的组件中:AngularFireStorage 然后调用

this.task = this.storage.upload(this.path, file, { customMetadata });
Run Code Online (Sandbox Code Playgroud)

如何选择一个存储桶将文件上传到它

小智 3

在文档中你可以看到:

// Get a non-default Storage bucket
var storage = firebase.app().storage('gs://my-custom-bucket');
Run Code Online (Sandbox Code Playgroud)

您必须定义的存储的引用是这样的:

var storageRef = firebase.app().storage('my-custom-bucket').ref();
Run Code Online (Sandbox Code Playgroud)