nodejs-storage: bucket.upload(filePath, options) producing an 404 error with detail-less description
Well, the title couldn’t be clearer, this is one of the detail-less error’s description I’ve ever seen, all I get is “Not Found” (after upgrading to 3.1.0 it also added the headers object, that also doesn’t means anything to me), I don’t even know what haven’t been found (but I can be sure it’s not about the file in filePath
, 'cause this produced another [detailed] error).
Hope that someone will be able to help me, 'cause I don’t even know where to start looking to fix this.
Environment details
- OS: macOS
- Node.js version: 10.12.0
- npm version: 6.10.2
@google-cloud/storage
version: 3.1.0
What I’ve already tried to do
- In https://console.cloud.google.com I’ve added the rule
Storage Admin
in addition toOwner
to the mail in thegoogle-key.json
file (that passed toStorage()
constructor). - Comment out the options, so it will be only
bucket.upload(filePath)
and may upload the file to the top level directory. - Chang storage rules to:
service firebase.storage {
match /b/{bucket}/o {
allow read: if true;
allow delete: if true;
allow write: if true;
}
}
and
service firebase.storage {
match /b/{bucket}/o {
allow read: if request.auth != null;
allow delete: if request.auth != null;
allow write: if request.auth != null;
}
}
Steps to reproduce
Call
bucket.upload(filePath, {
destination: destPath
}).then(() => {
res.end('Successfully uploaded!');
}).catch((err) => {
res.end('Failed to upload: ' + JSON.stringify(err));
});
and get this error in the catch()
calback:
Failed to upload:
{
"code":404,
"errors":[
{
"domain":"global",
"reason":"notFound",
"message":"Not Found"
}
],
"response":{
"headers":{
"alt-svc":"quic=\":443\"; ma=2592000; v=\"46,43,39\"",
"content-length":"165",
"content-type":"application/json; charset=UTF-8",
"date":"Thu, 15 Aug 2019 13:58:50 GMT",
"server":"UploadServer",
"vary":"Origin, X-Origin",
"x-guploader-uploadid":"AEnB2Ur6Hhd5uVLDCSH...A8pw7rD1-g"
}
},
"message":"Not Found"
}
Also, I’m getting some unclear message in the console (if thats related), don’t understand from what should I be “careful” and right now I’m using the emulator on my mac, so it’s not production:
⚠ Google API requested!
- URL: "https://www.googleapis.com/oauth2/v4/token"
- Be careful, this may be a production service.
⚠ Google API requested!
- URL: "https://www.googleapis.com/upload/storage/v1/b/my-projectf/o?uploadType=multipart&name=path%2to%2Ffile.jpg"
- Be careful, this may be a production service.
Thanks, Ido.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 21 (9 by maintainers)
My bad, I thought that
bucketName
is like theprojectId
, but I had to append to it.appspot.com
. So so sorry for wasting your time for that, really appreciate that you didn’t gave up and insisted that the issue is with thebucketName
. Thank you very much!You’re probably scrubbing out your bucket name, but I do have a mild concern over what “my-projectf” is that keeps appearing in the URL? Is that the actual bucket name?
I just had the same problem. It was because I was under the assumption that the bucket is the top level folder I can see in Firebase. But the bucket is really the project name and everything is inside that one bucket when using Firebase.
So the SDK was looking for
my-bucket
inside the default root bucket calledmy-project
because I did this:storageBucket: 'my-project.appspot.com'
and
FirebaseAdmin.storage().bucket('my-bucket')
But in the case of using Firebase, you have to add
my-bucket
in the filename and leave bucket() empty.Anyway, maybe the error message can be more clear? Seems like this happens more often, especially to users new to Firebase.
No problem, I’m glad we were both around at the same time to quickly talk it out! Let me know if anything else pops up 🥂
filePath
is the local file anddestPath
is the path to upload the file into Firebase Storage (e.g.images/image.jpg
). See alsoWhat I've already tried to do
.2 in the first comment.