0

I've used storage API in cloud function to upload some XML files as following:

await bucket.upload(filePath, {
        destination: fileName,
        resumable: true,
        metadata: {
            cacheControl: 'no-cache',
            metadata: {
                firebaseStorageDownloadTokens: uuidv4() //generate access token as I've found out on some other answers
            }
        }
    });

But then when I go to Firebase storage console to view the files uploaded, I'm unable to open them without manually creating new access token for them. I've tried generating download URL right after uploading as below

await bucket.file(fileName).getSignedUrl({
        action: 'read',
        expires: new Date().setDate(new Date().getDate() + 1) //expires after 24 hours
    });

but nothing changes. What should I do for now?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • What do you mean by "I'm unable to open the file without manually creating an access token on Firebase storage UI"? Please edit the question to explain what you're doing when you "open the file". There should be enough information in the question so that anyone can follow the same steps to reproduce the issue. – Doug Stevenson Dec 10 '20 at 07:34
  • @DougStevenson sorry for my bad English. What I'm trying to do is uploading files by cloud function, then go to Firebase console to view the uploaded contents. I see them, but I can't open, or download them if I don't create new access token. I've edited my question. Please tell me if there's still something uncleared. – user14717074 Dec 10 '20 at 07:40
  • It's a known issue that an image needs an access token before it can be loaded by the Firebase console. – Doug Stevenson Dec 10 '20 at 08:06
  • @DougStevenson so currently there is no storage API to generate access token & attach to file before uploading? – user14717074 Dec 10 '20 at 08:44
  • There actually is a trick to generate such a token yourself. See https://stackoverflow.com/a/63138999 – Frank van Puffelen Dec 10 '20 at 16:00

0 Answers0