0

I am making a thumbnail image using firebase functions, however, I tried two approaches to get the downloadURL of the resulted image but both I have different problems:

The first approach: I used the code below

const signedUrls = await bucket.file(thumbFilePath).getSignedUrl({
  action: "read",
  expires: "03-09-2491"
});

For this approach after some days, the url is no more valid even though the expiration date is very far, I couldn't find a proper solution and in meanwhile, I found another approach so I tried it.

the second approach: I used the code below

 // Uploading the thumbnail than make it public to be able to access it.
await bucket.upload(tempFilePath_des, {
    destination: thumbFilePath,
    metadata: metadata
  });

 await storage
    .bucket(fileBucket)
    .file(thumbFilePath)
    .makePublic();

thumbURL =
    "https://storage.cloud.google.com/" + fileBucket + "/" + thumbFilePath;
    
    

This approach works well when I use Google Auth, but when I use email auth the following error is thrown:

Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type text/html. See for more details.

Please, Any help?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ana Houa
  • 901
  • 1
  • 8
  • 19

1 Answers1

0

I found another approach that seems to be working in this post

when uploading the image we need to give it a UUID or we can retrieve it if we want from the metadata of the file using the following

const [metadata] = await storage.bucket(fileBucket).file(filePath).getMetadata();
const uuid = metadata.metadata.firebaseStorageDownloadTokens

than we construct our URL, here my working code:

  const UUID = require('uuid/v4');

  let uuid = UUID()

  await bucket.upload(tempFilePath_des, {
    destination: thumbFilePath,
    metadata : {
      contentType: metdata.contentType,
      metadata: {
        firebaseStorageDownloadTokens: uuid
      }
    }
  });

  thumbURL =
  "https://firebasestorage.googleapis.com/v0/b/" + fileBucket + "/o/" + encodeURIComponent(thumbFilePath) + "?alt=media&token=" + uuid;
Ana Houa
  • 901
  • 1
  • 8
  • 19