Reputation: 111
I need to fetch images from rest API (base64) and write individual images into Firebase Cloud Storage. After image is successfully written, write log into Firebase Realtime Database.
Well, I initialized Firebase app (Cloud Functions) with AdminSDK, because I need some admin features (for instance bypassing Realtime Database rules). According to Firebase documentation, if I use AdminSDK, then for manipulating Cloud Storage I must use "@google-cloud/storage".
So I looked up documentation for "@google-cloud/storage" and found out that for uploading files I have to call method ".upload" and specify path to file as argument.
The problem is I don't have path to that file because I have it as base64 string. I can't generate path for it, because nodeJS doesn't have method URL.createObjectURL and polyfiling that method is impossible. Also writing that image to filesystem is not solution, because Cloud Functions is read-only environment.
Polyfiling URL.createObjectURL, but it didn't work
Use nodeJS module FS to write images from REST API to filesystem, upload them to Cloud Storage and then remove them.
Upvotes: 0
Views: 372
Reputation: 111
My second solution (writing temporary file using fs) was almost right, but I forgot to specify file destination to /tmp
. In Firebase Cloud Functions is everything but /tmp
read-only storage.
Upvotes: 2