Why there's not storage access on the server?
IonicaBizau opened this issue · 3 comments
nicolasgarnier commented
Answered on SO!
IonicaBizau commented
@nicolasgarnier Thank you for the answer, but can you answer my comments as well? 😁
I'm still a bit confused...
Cheers!
IonicaBizau commented
@nicolasgarnier Thanks once again for help. And thanks from @coltaemanuela too! 🍰
The minimal code for uploading a file is:
"use strict";
const gcloud = require("gcloud");
const PROJECT_ID = "<project-id>";
let storage = gcloud.storage({
projectId: PROJECT_ID,
keyFilename: 'auth.json'
});
let bucket = storage.bucket(`${PROJECT_ID}.appspot.com`)
bucket.upload("1.jpg", (err, file) => {
if (err) { return console.error(err); }
let publicUrl = `https://firebasestorage.googleapis.com/v0/b/${PROJECT_ID}.appspot.com/o/${file.metadata.name}?alt=media`;
console.log(publicUrl);
});