Day008
Firebase storage
I followed a youtube video to access firebase storage.
It uses firebase web api to do the access. The process is quite smooth. Nothing stupid blocked the way.
— — — — — — — — — — — — — — — — — — — — —
Above tutorial teaches us how to access firebase storage from frontend. Then, how about accessing from backend, say, a nodejs server. It turns out the stupid thing is here.
Firebase Storage is not included in the server side Firebase npm module. Instead, you can use the gcloud Node.js client.
Under the hood, firebase storage is using google cloud storage as its base. So, if you start using firebase storage, you can see the same bucket appears in google cloud console.
I followed the instruction in
and got below error:
{ errors: [ { domain: ‘global’, reason: ‘forbidden’, message: ‘Forbidden’ } ],
code: 403,
message: ‘Forbidden’ }Cloud Storage uses the standard HTTP error reporting format for the JSON API. Successful requests return HTTP status…cloud.google.com
I suspect it is because I did not enable billing in the cloud console. By the logic in gcloud module, I am meant to be forbidden to access the bucket, even if I had successfully accessed through firebase web api and the rules set in firebase console is always true to allow access, like the setting did in the tutorial (i.e. “if true”).
— — — — — — — — — — — — — — — — — — — — —
ref:
It uses multer to upload file through form-data and then upload the file to google cloud storage from nodejs server:
https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-storage
— — — — — — — — — — — — — — — — — — — — —
ref:
https://cloud.google.com/appengine/docs/flexible/nodejs/quickstart
https://googlecloudplatform.github.io/gcloud-node/#/
https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.36.0/storage
https://cloud.google.com/nodejs/getting-started/using-cloud-storage