0

I am using Firebase Cloud Storage.

I know how to get the URL of a downloaded file (tags.txt) using Firebase SDK function running on a client javascript :

storage.ref('tags.txt').getDownloadURL().then((url) => {
      console.log(url);
    }); 

I want to get the downloadURL from Node.JS . I do know this function does not exists for Node.JS

However, In Google Cloud Platform you can get the following key/value pair : firebaseStorageDownloadTokens : 0ea9a60a-7719-4c6b-9cb5-7fcf69d7c633, the value being the token you want. From this token I can easily build the downloadURL I need.

The path to get there is:

Cloud Storage / "Bucket name" / Bucket details / tags.txt / EDIT METADATA / Custom metadata.

I try this code to access this metadata :

async function getBucketMetadata() {

    const bucketName = "gs://tags.appspot.com";

    try {
        // Get Bucket Metadata
        let metadata = await admin.storage().bucket(bucketName).file('tags.txt').getMetadata();
        console.log(metadata)
    }

    catch (err) {
        console.log(err.message)
    }

} 

I got keys/values (not a real project though) info such as:

bucket:'tags.appspot.com'
contentType:'text/plain'
crc32c:'Y1Sdxw=='
etag:'CI1EETD18Co9vECEAE='
generation:'162694124484794756'
id:'tags-admin.appspot.com/tags.txt/162694431484794756'
kind:'storage#object'
md5Hash:'P1YSFER4xSf5p0/KWrdQWx1z1Lyg=='
mediaLink:'https://storage.googleapis.com/download/storage/v1/b/tags-admin.appspot.com/o/tags.txt?generation=162694443184794756&alt=media'
metageneration:'1'
name:'tags.txt'
selfLink:'https://www.googleapis.com/storage/v1/b/tags-admin.appspot.com/o/tags.txt'
size:'5211247'
storageClass:'STANDARD'
timeCreated:'2021-07-22T09:01:24.862Z'
timeStorageClassUpdated:'2021-07-22T09:01:24.862Z'
updated:'2021-07-22T09:01:24.862Z'

But nothing regarding the key/value pair I want : firebaseStorageDownloadTokens : 0ea9a60a-7719-4c6b-9cb5-7fcf69d7c633

If the key/value can be seen on Google Cloud Platform , I do believe the key/value is also accessible via some code.

Your help is appreciated.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Pierre
  • 21
  • 3
  • I suggest reading through: https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase – Doug Stevenson Jul 23 '21 at 04:15
  • I don't think you can retrieve those tokens for existing object, but if you add them while uploading the file then you can set your own token. – Dharmaraj Jul 23 '21 at 04:16

1 Answers1

0

I mixed up two projects. I re-tried it, and its work pretty nicely. Using this method I can retrieve the file token and build the file URL around it on the back-end. The front-end function getDownloadURL() is not longer required.

Thanks for your help anyway.

The code become:

async function getBucketMetadata() {

    const bucketName = "gs://tags.appspot.com";

    try {
        // Get Bucket Metadata
        let metadata = await admin.storage().bucket(bucketName).file('tags.txt').getMetadata();
        console.log(metadata[0].metadata.firebaseStorageDownloadTokens)
    }

    catch (err) {
        console.log(err.message)
    }

}
Pierre
  • 21
  • 3