0

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?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Omar
  • 2,726
  • 2
  • 32
  • 65

1 Answers1

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}`;
Omar
  • 2,726
  • 2
  • 32
  • 65