Firebase Storage Admin Error:400 Invalid Bucket Name
I'm trying to use firebase functions to do maintenance of my database and storage. Basically remove some old entries from one ref/bucket to another after they expire.
The database part works great. However, the storage part, not so much. Here's how I initialize everything in my code:
var functions = require('firebase-functions');
var admin = require("firebase-admin");
var serviceAccount = require('./my-app-bla-bla.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://my-app.firebaseio.com',
storageBucket: 'gs://my-app.appspot.com'
});
Then in the cron job that cleans the database and storage, I have the following (this is only some small relevant part):
const st = admin.storage();
st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey).create(function(error, bucket, apiResponse) {
if (error) {
console.log("Couldn't create an OldListing bucket: " + error.code);
console.log(apiResponse);
} else {
console.log("Created OldListing bucket");
}
});
This last piece of code triggers the error and gives me the following log:
Couldn't create an OldListing bucket: 400
{ error:
{ errors: [ [Object] ],
code: 400,
message: 'Invalid bucket name: 'my-app.appspot.com/old-listings/SomeUniqueID'' } }
Because I'm running this code for the first time, the folder old-listings does not exist yet. So I though maybe I should create its bucket on its own first. It gives me the same error.
I also tried using the buckets without the gs link, e.g. st.bucket("old-listings/"+listingKey) instead of st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey). Still gives me the same error.
so what exactly is missing here? What am I doing wrong?
Edit 1
I tried adding the following code snippet at the beginning of my cron function. In an effort to better understand what's going on.
admin.storage().bucket("my-app.appspot.com").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Top Bucket Exists");
} else {
console.log("Top Bucket Does Not Exist");
}
} else {
console.log("Top Bucket Error " + error.code);
}
});
admin.storage().bucket("my-app.appspot.com/listings").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Listings Bucket Exists");
} else {
console.log("Listings Bucket Does Not Exist");
}
} else {
console.log("Listings Bucket Error " + error.code);
}
});
I get the following in my log:
Top Bucket Exists
Listing Bucket Error undefined
Of course I already have a folder called listings in my firebase storage. So why on earth would the second bucket be undefined?
firebase google-cloud-functions firebase-storage firebase-admin
add a comment |
I'm trying to use firebase functions to do maintenance of my database and storage. Basically remove some old entries from one ref/bucket to another after they expire.
The database part works great. However, the storage part, not so much. Here's how I initialize everything in my code:
var functions = require('firebase-functions');
var admin = require("firebase-admin");
var serviceAccount = require('./my-app-bla-bla.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://my-app.firebaseio.com',
storageBucket: 'gs://my-app.appspot.com'
});
Then in the cron job that cleans the database and storage, I have the following (this is only some small relevant part):
const st = admin.storage();
st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey).create(function(error, bucket, apiResponse) {
if (error) {
console.log("Couldn't create an OldListing bucket: " + error.code);
console.log(apiResponse);
} else {
console.log("Created OldListing bucket");
}
});
This last piece of code triggers the error and gives me the following log:
Couldn't create an OldListing bucket: 400
{ error:
{ errors: [ [Object] ],
code: 400,
message: 'Invalid bucket name: 'my-app.appspot.com/old-listings/SomeUniqueID'' } }
Because I'm running this code for the first time, the folder old-listings does not exist yet. So I though maybe I should create its bucket on its own first. It gives me the same error.
I also tried using the buckets without the gs link, e.g. st.bucket("old-listings/"+listingKey) instead of st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey). Still gives me the same error.
so what exactly is missing here? What am I doing wrong?
Edit 1
I tried adding the following code snippet at the beginning of my cron function. In an effort to better understand what's going on.
admin.storage().bucket("my-app.appspot.com").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Top Bucket Exists");
} else {
console.log("Top Bucket Does Not Exist");
}
} else {
console.log("Top Bucket Error " + error.code);
}
});
admin.storage().bucket("my-app.appspot.com/listings").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Listings Bucket Exists");
} else {
console.log("Listings Bucket Does Not Exist");
}
} else {
console.log("Listings Bucket Error " + error.code);
}
});
I get the following in my log:
Top Bucket Exists
Listing Bucket Error undefined
Of course I already have a folder called listings in my firebase storage. So why on earth would the second bucket be undefined?
firebase google-cloud-functions firebase-storage firebase-admin
add a comment |
I'm trying to use firebase functions to do maintenance of my database and storage. Basically remove some old entries from one ref/bucket to another after they expire.
The database part works great. However, the storage part, not so much. Here's how I initialize everything in my code:
var functions = require('firebase-functions');
var admin = require("firebase-admin");
var serviceAccount = require('./my-app-bla-bla.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://my-app.firebaseio.com',
storageBucket: 'gs://my-app.appspot.com'
});
Then in the cron job that cleans the database and storage, I have the following (this is only some small relevant part):
const st = admin.storage();
st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey).create(function(error, bucket, apiResponse) {
if (error) {
console.log("Couldn't create an OldListing bucket: " + error.code);
console.log(apiResponse);
} else {
console.log("Created OldListing bucket");
}
});
This last piece of code triggers the error and gives me the following log:
Couldn't create an OldListing bucket: 400
{ error:
{ errors: [ [Object] ],
code: 400,
message: 'Invalid bucket name: 'my-app.appspot.com/old-listings/SomeUniqueID'' } }
Because I'm running this code for the first time, the folder old-listings does not exist yet. So I though maybe I should create its bucket on its own first. It gives me the same error.
I also tried using the buckets without the gs link, e.g. st.bucket("old-listings/"+listingKey) instead of st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey). Still gives me the same error.
so what exactly is missing here? What am I doing wrong?
Edit 1
I tried adding the following code snippet at the beginning of my cron function. In an effort to better understand what's going on.
admin.storage().bucket("my-app.appspot.com").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Top Bucket Exists");
} else {
console.log("Top Bucket Does Not Exist");
}
} else {
console.log("Top Bucket Error " + error.code);
}
});
admin.storage().bucket("my-app.appspot.com/listings").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Listings Bucket Exists");
} else {
console.log("Listings Bucket Does Not Exist");
}
} else {
console.log("Listings Bucket Error " + error.code);
}
});
I get the following in my log:
Top Bucket Exists
Listing Bucket Error undefined
Of course I already have a folder called listings in my firebase storage. So why on earth would the second bucket be undefined?
firebase google-cloud-functions firebase-storage firebase-admin
I'm trying to use firebase functions to do maintenance of my database and storage. Basically remove some old entries from one ref/bucket to another after they expire.
The database part works great. However, the storage part, not so much. Here's how I initialize everything in my code:
var functions = require('firebase-functions');
var admin = require("firebase-admin");
var serviceAccount = require('./my-app-bla-bla.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://my-app.firebaseio.com',
storageBucket: 'gs://my-app.appspot.com'
});
Then in the cron job that cleans the database and storage, I have the following (this is only some small relevant part):
const st = admin.storage();
st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey).create(function(error, bucket, apiResponse) {
if (error) {
console.log("Couldn't create an OldListing bucket: " + error.code);
console.log(apiResponse);
} else {
console.log("Created OldListing bucket");
}
});
This last piece of code triggers the error and gives me the following log:
Couldn't create an OldListing bucket: 400
{ error:
{ errors: [ [Object] ],
code: 400,
message: 'Invalid bucket name: 'my-app.appspot.com/old-listings/SomeUniqueID'' } }
Because I'm running this code for the first time, the folder old-listings does not exist yet. So I though maybe I should create its bucket on its own first. It gives me the same error.
I also tried using the buckets without the gs link, e.g. st.bucket("old-listings/"+listingKey) instead of st.bucket("gs://my-app.appspot.com/old-listings/"+listingKey). Still gives me the same error.
so what exactly is missing here? What am I doing wrong?
Edit 1
I tried adding the following code snippet at the beginning of my cron function. In an effort to better understand what's going on.
admin.storage().bucket("my-app.appspot.com").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Top Bucket Exists");
} else {
console.log("Top Bucket Does Not Exist");
}
} else {
console.log("Top Bucket Error " + error.code);
}
});
admin.storage().bucket("my-app.appspot.com/listings").exists(function(error, exists) {
if (!error) {
if (exists) {
console.log("Listings Bucket Exists");
} else {
console.log("Listings Bucket Does Not Exist");
}
} else {
console.log("Listings Bucket Error " + error.code);
}
});
I get the following in my log:
Top Bucket Exists
Listing Bucket Error undefined
Of course I already have a folder called listings in my firebase storage. So why on earth would the second bucket be undefined?
firebase google-cloud-functions firebase-storage firebase-admin
firebase google-cloud-functions firebase-storage firebase-admin
edited Nov 26 '18 at 7:14
ProWi
asked Nov 26 '18 at 2:54
ProWiProWi
4041125
4041125
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you build a name to a bucket, it's not supposed to contain file path components in it, It should just be the unique name of the bucket - the container for all your objects. If you want to reference a file in the bucket, use the file() method on the bucket object to get a File object to deal with.
const st = admin.storage();
const bucket = st.bucket('name-of-your-bucket');
const file = bucket.file('name-of-your-file');
1
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
2
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
add a comment |
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%2f53474205%2ffirebase-storage-admin-error400-invalid-bucket-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you build a name to a bucket, it's not supposed to contain file path components in it, It should just be the unique name of the bucket - the container for all your objects. If you want to reference a file in the bucket, use the file() method on the bucket object to get a File object to deal with.
const st = admin.storage();
const bucket = st.bucket('name-of-your-bucket');
const file = bucket.file('name-of-your-file');
1
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
2
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
add a comment |
When you build a name to a bucket, it's not supposed to contain file path components in it, It should just be the unique name of the bucket - the container for all your objects. If you want to reference a file in the bucket, use the file() method on the bucket object to get a File object to deal with.
const st = admin.storage();
const bucket = st.bucket('name-of-your-bucket');
const file = bucket.file('name-of-your-file');
1
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
2
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
add a comment |
When you build a name to a bucket, it's not supposed to contain file path components in it, It should just be the unique name of the bucket - the container for all your objects. If you want to reference a file in the bucket, use the file() method on the bucket object to get a File object to deal with.
const st = admin.storage();
const bucket = st.bucket('name-of-your-bucket');
const file = bucket.file('name-of-your-file');
When you build a name to a bucket, it's not supposed to contain file path components in it, It should just be the unique name of the bucket - the container for all your objects. If you want to reference a file in the bucket, use the file() method on the bucket object to get a File object to deal with.
const st = admin.storage();
const bucket = st.bucket('name-of-your-bucket');
const file = bucket.file('name-of-your-file');
answered Nov 26 '18 at 8:18
Doug StevensonDoug Stevenson
79.3k995113
79.3k995113
1
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
2
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
add a comment |
1
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
2
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
1
1
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
So my understanding that a bucket is the same as a directory is wrong. It's one bucket for the whole thing. So that means a file has to be identified by its full path inside the bucket, for example "listings/name.png". Is my understanding correct?
– ProWi
Nov 26 '18 at 8:24
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
But then what if I want to deal with directories in the storage, not files?
– ProWi
Nov 26 '18 at 8:25
2
2
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
There are not really any "directories" in Cloud Storage. There are just files with names that look like they contain directories, to help your mental model of the organization of files. Notice that there is a lack of API for listing files within "directories", because directories don't exist. There may be ability to list files within "directories" in the future, but there still won't actually be any directories, just new indexes of your files within your concept of a "directory".
– Doug Stevenson
Nov 26 '18 at 8:26
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
Understood, that requires some changes in my code. Thanks a lot.
– ProWi
Nov 26 '18 at 8:29
add a comment |
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%2f53474205%2ffirebase-storage-admin-error400-invalid-bucket-name%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