0

I need to get download URL like this one for the image in my firebase storage:

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

in iOS, I can get the link using

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)
        }
    }

but at this time I need to get the link in background trigger using cloud function. the code below will be triggered if an image uploaded to Firebase Storage

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


    })
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Agung Laksana
  • 781
  • 1
  • 12
  • 26
  • Add this code to your function: `console.log(object.mediaLink);` Then upload a file and check the logs. According to the [docs](https://firebase.google.com/docs/reference/functions/functions.storage.ObjectMetadata), object should be an ObjectMetadata. – James Poag Sep 11 '18 at 11:37
  • 1
    To get the download URL from server-side code, you call `getSignedUrl()` on the file. See https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase – Frank van Puffelen Sep 11 '18 at 13:31

0 Answers0