使用云功能将图像以编程方式上传到Firebase存储后,如何获取下载URL?

时间:2018-09-11 10:50:55

标签: node.js firebase google-cloud-storage google-cloud-functions firebase-storage

我需要为Firebase存储中的图像获取像这样的下载URL:

  

https://firebasestorage.googleapis.com/v0/b/xxxxxxxxn.appspot.com/o/profilePicture%2F0JAKUtQYN6wTuAo5D7Xn.jpg?alt=media&token=54143e9d-db25-4b7b-a8b5-1f32c2ab14fd

在iOS中,我可以使用

来获取链接
import Firebase

Storage.storage().reference()child(path).downloadURL { (urlStorage, error) in
        if let error = error {
            print("there is an error while getting downloadURL String firebase storage: \(error.localizedDescription)")
            completion(nil)
        } else {
            print("successfully get downloadURL String firebase storage firebase storage")
            completion(urlStorage?.absoluteString)
        }
    }

但是这时我需要使用云功能在后台触发中获取链接。如果将图片上传到Firebase存储,则会触发以下代码

import * as admin from 'firebase-admin'

const defaultStorage = admin.storage()
admin.initializeApp()

export const updateUserProfileImagePathAfterUploadingImage = functions.storage.object().onFinalize(async (object) => {

      // I don't know what to do in here. I can't access 'child' in 'defaultStorage' to access download URL like in the iOS code


    })

0 个答案:

没有答案