I am a huge proponent of Firebase and interestingly, up until recently, I had never used Firebase Storage. Instead, I usually opt for Amazon’s S3 service which I am familiar with. Wanting to keep everything in the one service is appealing to me, so I started to add in file upload functionality in a Firebase Cloud Function.
It was not as straightforward as I would have hoped. I am using Express with Firebase and the Google Cloud NPM package as documented in code examples and numerous tutorials.
After adding in the @google-cloud/storage
package into my Cloud Function file, I plumbed it all in and figured it would work. Then I got this vague error.
{
"errors": [
"domain": "global",
"reason": "notFound",
"message": "Not Found"
]
}
Even with an error message, I was left scratching my head. I had nothing I could really Google, looking through the documentation failed to give me the answer and then out of frustration and trial and error, I discovered the cause.
This is the code that I had setting up my storage object and bucket instance. Tell me if you can spot the problem.
import { Storage } from '@google-cloud/storage';
const storage = new Storage();
const bucket = storage.bucket('steem-engine-dex');
The problem is with the bucket name, I also had to add in the project ID as well.
storage.bucket('steem-engine-dex.appspot.com', {
userProject: 'steem-engine-dex'
});
The bucket name in Firebase requires adding .appspot.com
into the bucket name and sure enough, if you go into Firebase itself and into the Storage section, you’ll notice something that points to this.
The bucket name after the protocol gs://
actually has the bucket name with appspot.com
in it. Unless I am blind, nowhere does it mention any of this in the documentation, it really tripped me up.
I wasted a lot of time working this out. So, hopefully, if you have experienced the same issue, this blog post saved you a few hours or days worth of wasted work. Happy coding.
In my case I had a bucket name + some short code + .appspot.com
I couldn’t find this explanation anywhere.
Thank you very much!