-
Notifications
You must be signed in to change notification settings - Fork 927
FR: Storage for node.js #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is definitely on our radar. There's stuff that many developers would want to do in a Node.js environment that doesn't even exist in the current Storage JS API, like file downloads. As you alluded to, https://github.com/GoogleCloudPlatform/google-cloud-node generally works as a replacement for server-side use cases where you can use service account credentials. The API is different, but it lets you do things the JS API doesn't support right now (file downloads!). |
The Firebase Admin SDK for Node has recently added support for Storage by wrapping the Google Cloud Storage libraries: https://firebase.google.com/docs/storage/admin/start. This makes it a lot easier to integrate GCS with Firebase (as it supports Firebase Authentication). While this integration does not unify the API surface, it simplifies the initial setup. |
Firebase js sdk has now support for nodejs #221. Thank you for that!! |
@MatiasConTilde could you please provide an example on how to use Google Cloud to access Firebase Storage? I tried it but I'm getting an error:
My Firebase Storage is public and I'm not authenticating, so I think it should work. I have never used Google Cloud directly, do I have to create an account there and configure it too? I tried setting an incorrect bucket and I got a different error, so I guess at least that part is correct. |
Why it is not possible to upload with this configuration to any bucket? I know I can accomplish upload with google cloud storage api but than I need public and private key generated from google cloud platform. |
We are investigating what it would take to ship a Firebase Storage SDK for Node (with third-party auth), but we cannot promise when or if this will be available soon. |
Thank you for the fast answer, but the point is that I can upload to storage from frontend(Angular 2+) application only with configuration I mentioned the same thing happens with firestore or RealTime database it is possible to upload from frontend. I am very interested why it is not possible from backend side. With node.js or .NET(C#). It requires me before I want to upload to storage or firestore to be authenticated. |
Any updates on this? |
We have not yet been able to prioritize this. |
Old issue but a goodie .. currently running into issues around this while working with iot (insecure) and 3rd party credentials. Workaround is exceptionally obtuse. A standard, rules-respecting and metadata applying API, even with major caveats, would be fantastic! |
Answering my own comment .. patching the storage library with an XHR polyfill actually appears to work (Node 15 / minimal testing so far). Specifically I've installed xmlhttprequest-ssl and imported it at the top of the storage module (in my case line 5 in var XMLHttpRequest = require("xmlhttprequest-ssl").XMLHttpRequest; Back in the app I import import { firebase } from "@firebase/app";
import "@firebase/storage";
/* include Firebase setup, etc. */
const filename = 'offline-user-generated-image.jpg';
const file = fs.readFileSync(filename); // for brevity only
const ref = firebase.storage().ref().child(`test/${filename}`);
// use the buffer's underlying arraybuffer
ref.put(file.buffer, {
contentType: 'image/jpg', // defaults to 'application/octet-stream'
customMetadata: {
uid: 'abc123', // for enhanced security rules
},
})
.then(() => console.log('done'))
.catch(e => console.log(e)); Storage rules apply to uploads (woop!) and security tokens and custom metadata are applied as expected. Also tested with `putString'. This solves some fairly drastic workarounds for my use case, as it means I can keep my logic/auth/etc. entirely within the Firebase ecosystem. Keen to hear others thoughts. Note: I'm using patch-package to ensure the patch stays intact across installs / upgrades. Update: I had to further patch the storage module (to clear an unresolved timeout) to allow the node process to complete successfully ... See PR #4266 |
My use case is uploading files from a cli without needing to setup a server I think that it shouldn't require too much effort, just polyfill Currently i am doing this, upload works but node never exits global.XMLHttpRequest = require('xmlhttprequest-ssl').XMLHttpRequest
import { firebase } from '@firebase/app'
import '@firebase/storage'
import '@firebase/auth' |
This will be available with the next release of Firebase. You should be able to run the Storage SDK in Node with no additional setup. The Node implementation does not support fine-grained upload progress indications, as upload progress is only available via XMLHTTPRequest. You will still receive some upload progress events for large files as we use chunked uploads. |
There is a way to use it with Google Cloud, but it is a bit complicated and firebase storage directly for web is much easier and convenient to use.
The text was updated successfully, but these errors were encountered: