更改默认存储桶后如何上传图像
How to upload an image after changing the default bucket
我试图将默认存储桶更改为 firestorage,我在互联网上进行了查找,并在 firebase 页面上找到了以下代码:
bucket2 = firebase.app().storage(bucket);
不过,之前我用的是:
this.afStorage.upload(remakeNewPath, file);
进行上传。现在,如果我这样做:
this.bucket2.upload(remakeNewPath, file);
它不再起作用了,bucket2 的值似乎不像 this.afStorage 那样具有 属性 上传。既然我使用的是不同的方式,我将如何上传它?
是的,此方法中没有称为上传的功能。
上传图片到新路径需要使用以下代码:
firebase.storage().ref().child(remakeNewPath).put(file);
这里的 remakeNewPath 是路径,您需要在配置中定义用于 firebase 的存储桶。
从 documentation for AngularFire2 来看,您似乎可以设置自定义存储桶:
import {AngularFireStorageModule, BUCKET } from '@angular/fire/storage';
@NgModule({
providers: [
{ provide: BUCKET, useValue: 'my-bucket-name' }
],
...
})
export class AppModule {}
您可以使用 BUCKET
injection token to customize the storage bucket and afterwards use one of the following methods to upload blobs:put()
、putString()
、upload()
。
我试图将默认存储桶更改为 firestorage,我在互联网上进行了查找,并在 firebase 页面上找到了以下代码:
bucket2 = firebase.app().storage(bucket);
不过,之前我用的是:
this.afStorage.upload(remakeNewPath, file);
进行上传。现在,如果我这样做:
this.bucket2.upload(remakeNewPath, file);
它不再起作用了,bucket2 的值似乎不像 this.afStorage 那样具有 属性 上传。既然我使用的是不同的方式,我将如何上传它?
是的,此方法中没有称为上传的功能。
上传图片到新路径需要使用以下代码:
firebase.storage().ref().child(remakeNewPath).put(file);
这里的 remakeNewPath 是路径,您需要在配置中定义用于 firebase 的存储桶。
从 documentation for AngularFire2 来看,您似乎可以设置自定义存储桶:
import {AngularFireStorageModule, BUCKET } from '@angular/fire/storage';
@NgModule({
providers: [
{ provide: BUCKET, useValue: 'my-bucket-name' }
],
...
})
export class AppModule {}
您可以使用 BUCKET
injection token to customize the storage bucket and afterwards use one of the following methods to upload blobs:put()
、putString()
、upload()
。