How can i get an url to download the thumbnail image after it has being uploaded?
The code below is used in the example, but i'm not sure how to grab an url from this image.
bucket.upload(tempLocalThumbFile, {
destination: thumbFilePath
}).then(() => {
console.log('Thumbnail uploaded to Storage at', thumbFilePath);
});
@rodrigoreal You should be able to use getDownloadURL.
If you want to do it by hand, ammending the following to the beginning of your file path should work (replace <- your-bucket-name-here -> with your actual bucket name):
'https://storage.cloud.google.com/<- your-bucket-name-here ->/' // private prefix for files (requires you to be authed with google)
'https://storage.googleapis.com/<- your-bucket-name-here ->/'; // public prefix (your file must be set to public)
Also, you may want to use the issue template that is provided for this repo, or your issue may be closed.
I was avoiding to use the first option because the extra http request for every image, but 'https://storage.googleapis.com/<- your-bucket-name-here ->/' worked like a charm.
Thanks for the response and sorry for the issue is not being on the right template.
@prescottprue the getDownloadURL method is for the client javascript SDK. Do you know of any way to get the downloadURL using the Google Cloud Storage API?
@markgoho I just create the string with the bucket name as shown above
For others coming to this issue to find a solution, I needed to call .makePublic() on the uploaded file as seen below in order to access the object, and then assign it to an img.src later on:
const projectId = `<your project id from the console project settings>`;
const destination = `<the intended destination for your file>`;
await bucket.upload(tmpFilePath, {
destination,
}, (err, file) => {
if (err) return console.error(err);
file.makePublic();
});
const storageURL = `https://storage.googleapis.com/${projectId}.appspot.com/${destination}`;
await admin.database().ref(`/pictures/${pictureSlug}`).update({ storageURL });
@markgoho this does not work for me. After makePublic the url in mediaLink from file.getMetadata() works (But as download). The assembled storageURL does not work. I am trying to open the link in a browser. What works is the getSignedUrl() like in the generate-thumbnail example.
The firebase storage link works and is public available.
https://firebasestorage.googleapis.com/v0/b/${projectId}.appspot.com/o...
@rodrigoreal You should be able to use
getDownloadURL.If you want to do it by hand, ammending the following to the beginning of your file path should work (replace
<- your-bucket-name-here ->with your actual bucket name):'https://storage.cloud.google.com/<- your-bucket-name-here ->/' // private prefix for files (requires you to be authed with google) 'https://storage.googleapis.com/<- your-bucket-name-here ->/'; // public prefix (your file must be set to public)Also, you may want to use the issue template that is provided for this repo, or your issue may be closed.
This gives 403.
@rodrigoreal another solution:
https://firebasestorage.googleapis.com/v0/b/{projectId}.appspot.com/o/{filepath}?alt=media
Most helpful comment
@rodrigoreal You should be able to use
getDownloadURL.If you want to do it by hand, ammending the following to the beginning of your file path should work (replace
<- your-bucket-name-here ->with your actual bucket name):Also, you may want to use the issue template that is provided for this repo, or your issue may be closed.