1
votes

In the web sdk of firebase storage you can upload an image from Blob data. I have a nodeJS app and want to upload images from blob data to my storage bucket. In the docs it's recommended to use the admin SDK if running a node server environment. But i cannot find this feature in the firbase storage admin documentation.

Heres my code:

const admin = require('firebase-admin');
const serviceAccount = require(`./credentials/my-keyfile.json`);
const app = admin.initializeApp({ 
  credential: admin.credential.cert(serviceAccount) 
});
const storage = app.storage();

// Get Blob data from an external ImageUrl
const axios = require("axios");
const getBlobFromUrl = (url) => {
  const response = await axios.get(url, { responseType: "blob" });
  return response.data;
}

const blobData = getBlobFromUrl("https://images.unsplash.com/photo-1591476315349-faa1c8e6f567?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max")
// MY QUESTION -> how can i upload that blob data to my storage?
1

1 Answers

0
votes

The first link you have posted on uploading an image with Blob data contains information on how you would do it with the client sdk.

When you use the Admin SDK, the use case is for the backend, for example, cloud functions. What you have shown in your post is used for this use case.

For implementations on how to upload an image using the client sdk, check out some of the Quickstart guides as well as the code labs.

If you're working primarily with Blob, you can check out some libraries like busboy and send HTTP requests instead.