【问题标题】:How do I get an Ionic image URL from an image uploaded to Firebase?如何从上传到 Firebase 的图像中获取 Ionic 图像 URL?
【发布时间】:2018-11-10 12:43:00
【问题描述】:

我正在使用 Cordova 在 Ionic 中从手机上传图片:

async takePhoto(sourceType: number) {
    try {

        const options: CameraOptions = {
            quality: 50,
            targetHeight: 100,
            targetWidth: 100,
            destinationType: this.camera.DestinationType.DATA_URL,
            encodingType: this.camera.EncodingType.JPEG,
            mediaType: this.camera.MediaType.PICTURE,
            correctOrientation: true,
            sourceType: sourceType
        }
        const result = await this.camera.getPicture(options);
        const image = `data:image/jpeg;base64,${result}`;
        this.pictures = storage().ref('pictures/myphotos');
        this.pictures.putString(image, 'data_url');
        this.Url = this.pictures.getDownloadURL();
              }

catch(e){
  console.error(e);
}}

我正在尝试从以下位置获取项目:

<ion-label>Item Name</ion-label>
  <ion-input type="text" [(ngModel)]="shoppingItem.itemName"></ion-input>
</ion-item>

<ion-item>
  <ion-label>Amount / Day</ion-label>
  <ion-input type="text" [(ngModel)]="shoppingItem.itemFee"></ion-input>
</ion-item>

<ion-item>
  <ion-label>Description</ion-label>
  <ion-input type="text" [(ngModel)]="shoppingItem.itemDescription">
</ion-input>
</ion-item>

<form-upload></form-upload>
  <button ion-button (click)="takePhoto(0)"> Upload Photo</button>
  <button ion-button (click)="addShopppingItem(shoppingItem)"> Submit </button>

addShopppingItem(shoppingItem: ShoppingItem){
this.shoppingItemRef$.push({itemName:this.shoppingItem.itemName,
  itemFee:this.shoppingItem.itemFee,
  temDescription:this.shoppingItem.itemDescription,
  itemInstructions:this.shoppingItem.itemInstructions,
  itemCategory: this.shoppingItem.itemCategory,
  itemDelivery: this.shoppingItem.itemDelivery,
  url:this.Url
})

我正在获取这些项目,但我无法将图像的 URL 获取到正确的节点中。

我需要节点是这样的,以便稍后使用查询显示图像:

【问题讨论】:

    标签: angular firebase ionic-framework firebase-realtime-database ionic2


    【解决方案1】:

    我不明白您的问题...您是否从数据库中正确检索了 downloadUrl?

    【讨论】:

    • 我确实收到了 URL,但是以第一张图片的格式,我想以第二张图片的格式获取它,我只能在使用快照时才能获得,但我无法获取快照使用上面代码中的相机选项上传实例。从第一张图片中的节点,我希望能够使用 在离子列表中显示图片
    猜你喜欢
    • 2017-11-24
    • 1970-01-01
    • 2016-10-28
    • 2018-08-25
    • 2021-07-17
    • 2019-06-24
    • 2020-06-26
    • 2021-10-12
    • 2021-02-27
    相关资源
    最近更新 更多