From the course: React: Cloud-Powered Apps with Firebase

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Cloud Storage file upload

Cloud Storage file upload

From the course: React: Cloud-Powered Apps with Firebase

Start my 1-month free trial

Cloud Storage file upload

- With that in place, we need to implement now a function to upload the user image to cloud storage. Let's first export the fire based storage service for our app in config.js. Import fire base/storage. And we can export a new token here and call that storage, and we can get the storage service here. Head over now to user.js and we'll create a new function called upload image. It needs a user ID and the file to upload. And here it will actually create and return a new promise. We need the resolve and the reject functions. Let's create the file reference here. We need to create first a file path, which will be users/userid/profile-image. Now we can create the file reference, calling storage.ref and then grabbing that child reference using that file path. And let's make sure we import storage here. We now need to create the upload task, and we can do that by calling put on the file reference, giving it the file that we need…

Contents