I'm relatively new to firebase and currently working on node.js (react-electron) app, my goal is to display some picture which was stored in firebase-storage.
In my app, I know the internal firebase storage URL gs://myapp.appspot.com/folders/image.jpg
and want to get downloadableURL https://firebasestorage.googleapis.com/...
So here's the problem: I know that there is refFromURL()
and getDownloadURL()
method from firebase storage and I planned to do this
import firebase from 'firebase';
import config from './firebaseConfig.json';
firebase.initializeApp(config);
var storage = firebase.storage();
function fetchTrueImgsrc(internalSrc) {
if (internalSrc === undefined) return null;
return storage.refFromURL(internalSrc).getDownloadURL();
}
And I got this
Line 4: Uncaught TypeError: firebase__WEBPACK_IMPORTED_MODULE_1___default.a.storage is not a function
I have found out that firebase.storage() is no longer support for node.js and all of document on https://firebase.google.com/docs/storage/web/start
is totally useless for me
So the question is, how would I implement this in node.js client side if I can't use firebase.storage? please help.
I have tried:
const myappBucket='myapp.appspot.com';
import { Storage } from '@google-cloud/storage';
const bucket = new Storage().bucket(myappBucket);
const file = bucket.file(internalSrc);
file
.getSignedUrl({
action: 'read',
expires: '03-09-2491'
})
.then(signedUrls => {
console.log('signed URL', signedUrls[0]); // this will contain the picture's url
return;
})
.catch(err => console.error(err));
const myappBucket='myapp.appspot.com';
import config from './firebaseConfig.json';
import firebase_admin from 'firebase-admin';
firebase_admin.initializeApp(config);
var storage = firebase_admin.storage();
var bucket = storage.bucket(myappBucket);
bucket.file(internalSrc).getSignedUrl(
{
action: 'read',
expires: '03-09-2491'
},
function(err, url) {
if (err) {
console.error(err);
} else {
console.log('Download model DL url: ' + url);
}
}
);
Both got this error
SigningError: Unexpected error determining execution environment: Failed to fetch at GoogleAuth.
I tried to avoid Downgrading firebase to firebase@v4.7.0 but if there is no solution for this, I think i should try this too.
I'm using: - "@google-cloud/storage": "^2.5.0" - "firebase": "^6.0.2" - "firebase-admin": "^7.3.0" - "react": "^16.8.6" - "electron": "^3.0.10"
thanks.