Cannot set metadata on a Google Storage Object from Node.js using Firebase Admin
I am writing a Firebase app and I need to change something in the backend running Node.js
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: config.get("firebase.storage")
});
I get the bucket from initializing admin and am able to see the existing metadata from that file. Setting it doesn't work:
const myfile = {URL: "/users/1/demo.png"}; //this file exists
const bucket = admin.storage().bucket();
const [metadata] = await bucket.file(redeemable.URL).getMetadata();
console.log(metadata); //this works
if (!metadata.metadata.whitelist) metadata.metadata.whitelist = {};
metadata.metadata.whitelist[req.user.userId] = true;
await bucket.file(myfile.URL).setMetadata(metadata);
Shouldn't the firebase admin have access rights? I also don't get any error.
firebase google-cloud-storage firebase-storage
|
show 3 more comments
I am writing a Firebase app and I need to change something in the backend running Node.js
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: config.get("firebase.storage")
});
I get the bucket from initializing admin and am able to see the existing metadata from that file. Setting it doesn't work:
const myfile = {URL: "/users/1/demo.png"}; //this file exists
const bucket = admin.storage().bucket();
const [metadata] = await bucket.file(redeemable.URL).getMetadata();
console.log(metadata); //this works
if (!metadata.metadata.whitelist) metadata.metadata.whitelist = {};
metadata.metadata.whitelist[req.user.userId] = true;
await bucket.file(myfile.URL).setMetadata(metadata);
Shouldn't the firebase admin have access rights? I also don't get any error.
firebase google-cloud-storage firebase-storage
1
There's too much missing information here. What exactly doesn't work? Is there an error? What are the values of all the variables in here that we can't see? Try hardcoding values instead so we can see what you intend to do.
– Doug Stevenson
Jan 1 at 18:25
setMetadata does not work. bucket and file (the only variables) are correct I can see and console.log the file's metadata but when I set it, it doesn't. It is also missing from the official docs. No error
– arisalexis
Jan 2 at 13:59
Metadata does work. Without seeing all the exact values you're dealing with, there's nothing Stack Overflow can do do help. stackoverflow.com/help/mcve
– Doug Stevenson
Jan 2 at 17:20
I am very sorry to hear with authority that you are sure it works and that SO cannot help. Can you tell me what exact values do you need? The file string? I can never produce an example that works simply because it needs my access codes to my google storage server which cannot be published. Nothing else is missing. But it is missing from their official docs for Node.js and only mentions setting metadata from the gsutil tool. I did add more code to make it clearer.
– arisalexis
Jan 3 at 11:41
When you sayconsole.log(metadata)
works, what exactly does it do that meets your expectations? What exactly does the object look like that you're passing to setMetadata? Let's distill this code down to a single call to setMetadata to see if it receives the data you expect.
– Doug Stevenson
Jan 3 at 17:04
|
show 3 more comments
I am writing a Firebase app and I need to change something in the backend running Node.js
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: config.get("firebase.storage")
});
I get the bucket from initializing admin and am able to see the existing metadata from that file. Setting it doesn't work:
const myfile = {URL: "/users/1/demo.png"}; //this file exists
const bucket = admin.storage().bucket();
const [metadata] = await bucket.file(redeemable.URL).getMetadata();
console.log(metadata); //this works
if (!metadata.metadata.whitelist) metadata.metadata.whitelist = {};
metadata.metadata.whitelist[req.user.userId] = true;
await bucket.file(myfile.URL).setMetadata(metadata);
Shouldn't the firebase admin have access rights? I also don't get any error.
firebase google-cloud-storage firebase-storage
I am writing a Firebase app and I need to change something in the backend running Node.js
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: config.get("firebase.storage")
});
I get the bucket from initializing admin and am able to see the existing metadata from that file. Setting it doesn't work:
const myfile = {URL: "/users/1/demo.png"}; //this file exists
const bucket = admin.storage().bucket();
const [metadata] = await bucket.file(redeemable.URL).getMetadata();
console.log(metadata); //this works
if (!metadata.metadata.whitelist) metadata.metadata.whitelist = {};
metadata.metadata.whitelist[req.user.userId] = true;
await bucket.file(myfile.URL).setMetadata(metadata);
Shouldn't the firebase admin have access rights? I also don't get any error.
firebase google-cloud-storage firebase-storage
firebase google-cloud-storage firebase-storage
edited Jan 3 at 11:42
arisalexis
asked Jan 1 at 14:54
arisalexisarisalexis
1,0221329
1,0221329
1
There's too much missing information here. What exactly doesn't work? Is there an error? What are the values of all the variables in here that we can't see? Try hardcoding values instead so we can see what you intend to do.
– Doug Stevenson
Jan 1 at 18:25
setMetadata does not work. bucket and file (the only variables) are correct I can see and console.log the file's metadata but when I set it, it doesn't. It is also missing from the official docs. No error
– arisalexis
Jan 2 at 13:59
Metadata does work. Without seeing all the exact values you're dealing with, there's nothing Stack Overflow can do do help. stackoverflow.com/help/mcve
– Doug Stevenson
Jan 2 at 17:20
I am very sorry to hear with authority that you are sure it works and that SO cannot help. Can you tell me what exact values do you need? The file string? I can never produce an example that works simply because it needs my access codes to my google storage server which cannot be published. Nothing else is missing. But it is missing from their official docs for Node.js and only mentions setting metadata from the gsutil tool. I did add more code to make it clearer.
– arisalexis
Jan 3 at 11:41
When you sayconsole.log(metadata)
works, what exactly does it do that meets your expectations? What exactly does the object look like that you're passing to setMetadata? Let's distill this code down to a single call to setMetadata to see if it receives the data you expect.
– Doug Stevenson
Jan 3 at 17:04
|
show 3 more comments
1
There's too much missing information here. What exactly doesn't work? Is there an error? What are the values of all the variables in here that we can't see? Try hardcoding values instead so we can see what you intend to do.
– Doug Stevenson
Jan 1 at 18:25
setMetadata does not work. bucket and file (the only variables) are correct I can see and console.log the file's metadata but when I set it, it doesn't. It is also missing from the official docs. No error
– arisalexis
Jan 2 at 13:59
Metadata does work. Without seeing all the exact values you're dealing with, there's nothing Stack Overflow can do do help. stackoverflow.com/help/mcve
– Doug Stevenson
Jan 2 at 17:20
I am very sorry to hear with authority that you are sure it works and that SO cannot help. Can you tell me what exact values do you need? The file string? I can never produce an example that works simply because it needs my access codes to my google storage server which cannot be published. Nothing else is missing. But it is missing from their official docs for Node.js and only mentions setting metadata from the gsutil tool. I did add more code to make it clearer.
– arisalexis
Jan 3 at 11:41
When you sayconsole.log(metadata)
works, what exactly does it do that meets your expectations? What exactly does the object look like that you're passing to setMetadata? Let's distill this code down to a single call to setMetadata to see if it receives the data you expect.
– Doug Stevenson
Jan 3 at 17:04
1
1
There's too much missing information here. What exactly doesn't work? Is there an error? What are the values of all the variables in here that we can't see? Try hardcoding values instead so we can see what you intend to do.
– Doug Stevenson
Jan 1 at 18:25
There's too much missing information here. What exactly doesn't work? Is there an error? What are the values of all the variables in here that we can't see? Try hardcoding values instead so we can see what you intend to do.
– Doug Stevenson
Jan 1 at 18:25
setMetadata does not work. bucket and file (the only variables) are correct I can see and console.log the file's metadata but when I set it, it doesn't. It is also missing from the official docs. No error
– arisalexis
Jan 2 at 13:59
setMetadata does not work. bucket and file (the only variables) are correct I can see and console.log the file's metadata but when I set it, it doesn't. It is also missing from the official docs. No error
– arisalexis
Jan 2 at 13:59
Metadata does work. Without seeing all the exact values you're dealing with, there's nothing Stack Overflow can do do help. stackoverflow.com/help/mcve
– Doug Stevenson
Jan 2 at 17:20
Metadata does work. Without seeing all the exact values you're dealing with, there's nothing Stack Overflow can do do help. stackoverflow.com/help/mcve
– Doug Stevenson
Jan 2 at 17:20
I am very sorry to hear with authority that you are sure it works and that SO cannot help. Can you tell me what exact values do you need? The file string? I can never produce an example that works simply because it needs my access codes to my google storage server which cannot be published. Nothing else is missing. But it is missing from their official docs for Node.js and only mentions setting metadata from the gsutil tool. I did add more code to make it clearer.
– arisalexis
Jan 3 at 11:41
I am very sorry to hear with authority that you are sure it works and that SO cannot help. Can you tell me what exact values do you need? The file string? I can never produce an example that works simply because it needs my access codes to my google storage server which cannot be published. Nothing else is missing. But it is missing from their official docs for Node.js and only mentions setting metadata from the gsutil tool. I did add more code to make it clearer.
– arisalexis
Jan 3 at 11:41
When you say
console.log(metadata)
works, what exactly does it do that meets your expectations? What exactly does the object look like that you're passing to setMetadata? Let's distill this code down to a single call to setMetadata to see if it receives the data you expect.– Doug Stevenson
Jan 3 at 17:04
When you say
console.log(metadata)
works, what exactly does it do that meets your expectations? What exactly does the object look like that you're passing to setMetadata? Let's distill this code down to a single call to setMetadata to see if it receives the data you expect.– Doug Stevenson
Jan 3 at 17:04
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996442%2fcannot-set-metadata-on-a-google-storage-object-from-node-js-using-firebase-admin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996442%2fcannot-set-metadata-on-a-google-storage-object-from-node-js-using-firebase-admin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
There's too much missing information here. What exactly doesn't work? Is there an error? What are the values of all the variables in here that we can't see? Try hardcoding values instead so we can see what you intend to do.
– Doug Stevenson
Jan 1 at 18:25
setMetadata does not work. bucket and file (the only variables) are correct I can see and console.log the file's metadata but when I set it, it doesn't. It is also missing from the official docs. No error
– arisalexis
Jan 2 at 13:59
Metadata does work. Without seeing all the exact values you're dealing with, there's nothing Stack Overflow can do do help. stackoverflow.com/help/mcve
– Doug Stevenson
Jan 2 at 17:20
I am very sorry to hear with authority that you are sure it works and that SO cannot help. Can you tell me what exact values do you need? The file string? I can never produce an example that works simply because it needs my access codes to my google storage server which cannot be published. Nothing else is missing. But it is missing from their official docs for Node.js and only mentions setting metadata from the gsutil tool. I did add more code to make it clearer.
– arisalexis
Jan 3 at 11:41
When you say
console.log(metadata)
works, what exactly does it do that meets your expectations? What exactly does the object look like that you're passing to setMetadata? Let's distill this code down to a single call to setMetadata to see if it receives the data you expect.– Doug Stevenson
Jan 3 at 17:04