Introduction

Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app. You can read my previous article here to learn about Firebase CRUD operations.
Firebase
Firebase gives you functionality like analytics, databases, messaging, and crash reporting so you can move quickly and focus on your users.

Firebase is a back-end platform for building Web, Android, and iOS applications. It offers real-time database, different APIs, multiple authentication types, and hosting platforms. This is an introductory tutorial which covers the basics of the Firebase platform and explains how to deal with its various components and sub-components.
Build apps with Firebase
- Real-time Database
- Storage
- Notifications
- Authentication
- Hosting
Prerequisites
- Visual Studio 2017 or Later (Windows or Mac)
Setting up a Xamarin.Forms Project
Start by creating a new Xamarin.Forms project. You’ll learn more by going through the steps yourself, however, you can download the source code from here - https://github.com/susairajs/Xamarin-Firebase-Storage
Visual Studio 2019 has more options in the opening window. Clone or check out the code from any repository or open a project or solution for your computer.
Now, you need to click "Create a new project".
Now, filter by Project Type: Mobile
Choose the Mobile App (Xamarin. forms) project under C# and Mobile.
Name your app. You probably want your project and solution to use the same name as your app. Put it on your preferred location for projects and click "Create".
Now, select the blank app and target platforms - Android, iOS, and Windows (UWP).

Subsequently, go to the solution. In there, you get all the files and sources of your project (.NET Standard). Now, select XAML page and double-click to open the MainPage.Xaml page.
You now have a basic Xamarin.Forms app. Click the "Play" button to try it out.

Create a project in Firebase
In this step, create a project in Firebase. Go to the following link.
https://console.firebase.google.com/
Click "Add Project".
Now, give the project a name and select your country; then read the terms. Afterward, click "Create project".

Now, your project is ready; click "Continue".

In this step, choose Storage under the Project Overview.

Now, you need to change the following Storage Rules. Afterward, click "Publish".
- service firebase.storage {
- match /b/{bucket}/o {
- match /{allPaths=**} {
- allow read, write: if request.auth == null;
- }
- }
- }

Now, your Firebase Storage is ready. You can use your Storage API URI here.
Setting up the User Interface
Go to MainPage.Xaml and write the following code.
MainPage.xaml
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:XamarinFirebase"
- x:Class="XamarinFirebase.MainPage">
- <StackLayout>
- <StackLayout>
- <StackLayout HorizontalOptions="Center" VerticalOptions="Start">
- <Image x:Name="imgBanner" Source="banner.png" ></Image>
- <Image Margin="0,0,0,10" HeightRequest="100" Source="firebase.png" ></Image>
- <Label Margin="0,0,0,10" Text="Firebase Storage" FontAttributes="Bold" FontSize="Large" TextColor="Gray" HorizontalTextAlignment="Center" ></Label>
- <Image x:Name="imgChoosed" HeightRequest="150"></Image>
- <Entry x:Name="txtFileName" Placeholder="Enter FileName"></Entry>
- <StackLayout HorizontalOptions="CenterAndExpand" Orientation="Horizontal">
- <Button x:Name="btnPick" WidthRequest="200" Text="Pick" Clicked="BtnPick_Clicked"/>
- <Button x:Name="btnUpload" WidthRequest="200" Text="Upload" Clicked="BtnUpload_Clicked" />
- </StackLayout>
- <StackLayout HorizontalOptions="CenterAndExpand" Orientation="Horizontal">
- <Button x:Name="btnDownload" WidthRequest="200" Text="Download" Clicked="BtnDownload_Clicked" />
- <Button x:Name="btnDelete" WidthRequest="200" Text="Delete" Clicked="BtnDelete_Clicked" />
- </StackLayout>
- <Label x:Name="lblPath"></Label>
- </StackLayout>
- </StackLayout>
- </StackLayout>
- </ContentPage>
Click the "Play" button to try it out.

NuGet Packages
Now, add the following NuGet packages.
- Xam.Plugin.Media
- Firebase.Storage
Add FirebaseDatabase.net NuGet
Go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for Solution". Search for "FirebaseDatabase.net" and add the resultant package. Remember to install it for each project (.NET Standard, Android, iOS, and UWP).

Connect Firebase
Now, write the following code to connect to your Firebase Storage.
- using Firebase.Storage;
- FirebaseStorage firebaseStorage = new FirebaseStorage("xamarinfirebase-****.appspot.com");



Joaquin CorugedoPosted Oct 7, 2021, 3:33 PM
Hi! I get the following exception when I try to upload the image to Firestore: Firebase.Storage.FirebaseStorageException Mensaje = Exception occured while processing the request.Url: https://firebasestorage.googleapis.com/v0/b/xamarinfirebase-*****.appspot.com/o?name=XamarinMonkeys%2FScreenshot_20210731-174602_One%20UI%20Home_4.jpg Response: N/A
Maria EstradaPosted May 5, 2021, 11:48 PM
A question how can i load the image back into the image instead of uploading it
Lloyd PrattPosted Dec 24, 2020, 2:00 AM
I keep getting a "Java.Lang.RuntimeException: 'Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.companyname.xamarinfire" Message. I looked at your code which you put this statement on the outside of the <application> tag instead of inside. I actually copied your code and pasted it in and just changed to provider to my provider
Mayur GudiPosted Apr 27, 2020, 10:40 AM
Instead of images can I extract audio files especially .mp3 files ?
Shiwam karnPosted Mar 11, 2020, 10:10 AM
I am working in list view & in list view i have only url of that image then while deleting the list then how can i link that url to delete the image from Firebase Storage
Abdelwahed KOURROUPosted Nov 3, 2019, 11:46 AM
System.ObjectDisposedException: Cannot access a disposed object.
Abdelwahed KOURROUPosted Nov 3, 2019, 11:12 AM
I have this error when i want upload or store image :Unhandled Exception:System.ObjectDisposedException: <Timeout exceeded getting exception details> occurred
bhupesh beheraPosted Oct 2, 2019, 3:43 AM
How to get all the files from a folder
AjitPosted Feb 7, 2019, 6:31 AM
Im created an app in firebase also can you please elaborate it step by step??
AjitPosted Feb 7, 2019, 3:54 AM
Is it possible to see my xamarin.form crash analytics using firebase???
Puneet KankarPosted Jan 30, 2019, 3:00 AM
Nice article .........
Pratik ShirsePosted Jan 29, 2019, 9:50 AM
Please let us know how to use mssql
Pratik ShirsePosted Jan 29, 2019, 9:49 AM
Really is to very good tutorial for beginner...