'Firebase Admin => Storage upload => How to find a download url? [duplicate]
I am using firebase Admin SDK for Nodejs. To successfully upload files. Now i need to use the upload response to determine a download url to be saved in a database... This was easy enough on the frontend but admin doesnt seem to document this.
import { getStorage } from "firebase-admin/storage";
import { UploadResponse } from "@google-cloud/storage";
async function upload(localFilePath) {
const uploadResp: UploadResponse = await getStorage()
.bucket()
.upload(localFilePath);
// how can i use UploadResponse to determine a public download url?
return uploadResp;
}
how can i use UploadResponse to determine a public download url?
Solution 1:[1]
getSignedUrl was my solution
import { getStorage } from "firebase-admin/storage";
import { UploadResponse } from "@google-cloud/storage";
async function upload(localFilePath) {
const uploadResp: UploadResponse = await getStorage()
.bucket()
.upload(localFilePath);
const downloadUrl = await uploadResp[0].getSignedUrl({
action: "read",
expires: "03-09-2491",
});
return downloadUrl;
}
Edit This also works
const downloadUrl = `https://storage.googleapis.com/${bucket}/${location}`;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
