I have been trying to retrieve the download URL from the last 2 days. I searched a lot for getting the correct answer but I got all the older and unclear answers. I do not find any newer/perfect answer that's why I am posting this question here.
I am uploading a base64 image to firebase storage via admin-SDK through firebase functions. Below is the code which I am using to upload my base64 to firebase storage.
base64 = "mybase64imagestring";
let bufferStream = new stream.PassThrough();
bufferStream.end(new Buffer.from(base64, 'base64'));
// Retrieve default storage bucket
let bucket = admin.storage().bucket();
// Create a reference to the new image file
let file = bucket.file(`/jk_${dish.createdAt}.jpg`);
bufferStream.pipe(file.createWriteStream({
metadata: {
contentType: 'image/jpeg'
}
}))
.on('error', error => {
reject(`Error while uploading picture ${JSON.stringify(error)}`);
})
.on('finish', () => {
// The file upload is complete and i want to get download URL(which is not public and should not expire) here.
});
I tried the method "getSignedUrl" to get download URL as stated here but I found in comments and also on some other websites that link retrieved by getSignedUrl()
is expiring in a week. I want a permanent link that does not expire for at least a month. I found somewhere that I can use a public link that doesn't expire but I do not find any way that how to retrieve it. Also, I do not want to compromise security so I do not want to store public link.
After getting that link, I am going to store that on the database and from the database, I will access the image via that link. That's why I expect a link to do not expire.