Cloud Storage stores your files in a Google Cloud Storage bucket, making them accessible through both Firebase and Google Cloud. This allows you the flexibility to upload and download files from mobile clients via the Firebase SDKs, and do server-side processing such as image filtering or video transcoding using Google Cloud. Cloud Storage scales automatically, meaning that there's no need to migrate to any other provider.
In your android project add these dependencies to work with firebase storage.
implementation 'com.google.firebase:firebase-storage:19.1.1'
1. Add following components to your XML file:
Button (@+id/select): To select the image from device
ImageView: To display the selected image
TextView: To display the name of the image
Button(@+id/buttonNext): To upload the image and start next activity (if any)
2. Make an entry for select button in onClick() method of your java class. This creates a new Intent instance. The intent type is set to image, and its action is set to get some content. The intent creates an image chooser dialog that allows the user to search through the device gallery to select the image from the gallery.
3. startActivityForResult is used to receive the result, which is the selected image. To display this image, make use of a method called onActivityResult(). onActivityResult receives a request code, result code, and the data. Check in this method, if the request code equals PICK_IMAGE_REQUEST, with the result code equal to RESULT_OK and the data available. If all this is true, display the selected image in the ImageView below buttons.
4. In uploadImage() method, Firebase storage reference is taken and putFile() function is used to upload the image to firebase storage with success and failure listeners. If an image is uploaded than success toast is there otherwise failure toast is there.
The uploaded images can be found in the Storage section of Firebase under the folder /images.