0

Hey folks I have an existing API layer using google cloud functions, and I was looking a way to get the download url for an image in Cloud Storage using a specific api endpoint.

app.get('/api/images/:ref', async (req, res) => {
    const { ref } = req.params
    try {
        const bucket = admin.storage().bucket('bucket name')
        const path = ref
        const img = await bucket.file(path).download()
        return img
    } catch (error) { return res.status(500).json(error.mesasge) }
}
)

and my refernce path for an image is like foldername/randomID

Will this be possible through an api endpoint through passing params.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Shawin Mendis
  • 173
  • 2
  • 10
  • 1
    I edited the question to remove references to Firestore because you're not using that product here at all. If you meant Firebase, that is a different thing. What you are looking for is called a "signed URL" in Cloud Storage terms. – Doug Stevenson Feb 14 '21 at 07:55
  • Signed Url got it thanks for the clarification – Shawin Mendis Feb 15 '21 at 00:32

0 Answers0