更改默认存储桶后如何上传图像

时间:2020-06-27 12:56:23

标签: javascript firebase google-cloud-storage angularfire2

我正在尝试将默认存储桶更改为Firestorage,我在互联网上进行了查找,然后在firebase页面上找到了以下代码:

bucket2 = firebase.app().storage(bucket);

但是,以前我在使用:

this.afStorage.upload(remakeNewPath, file);

进行上传。现在,如果我这样做:

this.bucket2.upload(remakeNewPath, file);

它不再工作了,似乎bucket2的值没有这样的属性上载。afStorage确实如此。如果我现在使用不同的方式,该如何上传?

3 个答案:

答案 0 :(得分:1)

是的,此方法中没有称为上载的功能。

您需要使用以下代码将图片上传到新路径:

 firebase.storage().ref().child(remakeNewPath).put(file);

这里remakeNewPath是路径,您需要在用于Firebase的配置中定义存储桶。

答案 1 :(得分:0)

通过查看documentation for AngularFire2,您似乎可以使用以下方法设置自定义存储桶:

import {AngularFireStorageModule, BUCKET } from '@angular/fire/storage';

@NgModule({
  providers: [
    { provide: BUCKET, useValue: 'my-bucket-name' }
  ],
  ...
})
export class AppModule {}

答案 2 :(得分:0)

您可以使用BUCKET injection token to customize the storage bucket,然后再使用following methods to upload blobs中的一种:put()putString()upload()