A cross platform plugin for Firebase Storage. A wrapper for Xamarin.Firebase.iOS.Storage and Xamarin.Firebase.Storage.
Install Nuget package to each projects.
- Add GoogleService-Info.plist to iOS project. Select BundleResource as build action.
- Initialize as follows in AppDelegate.
Firebase.Core.App.Configure();
- Add google-services.json to Android project. Select GoogleServicesJson as build action. (If you can't select GoogleServicesJson, reload this android project.)
- Target framework version needs to be Android 10.0.
- Add the following into AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
await reference.PutBytesAsync(bytes);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
await reference.PutStreamAsync(stream);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
await reference.PutFileAsync(filePath);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var metadata = new MetadataChange
{
ContentType = "image/jpeg"
};
await reference.PutStreamAsync(stream, metadata);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var uploadProgress = new Progress<IUploadState>();
uploadProgress.ProgressChanged += (sender, e) =>
{
var progress = e.TotalByteCount > 0 ? 100.0 * e.BytesTransferred / e.TotalByteCount : 0;
};
await reference.PutStreamAsync(stream, progress: uploadProgress);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var cts = new CancellationTokenSource();
var task = Task.Run(async () =>
{
await Task.Delay(1000);
cts.Cancel();
});
await reference.PutStreamAsync(stream, cancellationToken: cts.Token);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var pts = new PauseTokenSource();
var task = Task.Run(async () =>
{
await Task.Delay(1000);
pts.Pause();
await Task.Delay(1000);
pts.Resume();
});
await reference.PutStreamAsync(stream, pauseToken: pts.Token);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var maxDownloadSizeBytes = 1024 * 1024;
var bytes = await reference.GetBytesAsync(maxDownloadSizeBytes);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var stream = await reference.GetStreamAsync();
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
await reference.GetFileAsync(filePath);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var downloadProgress = new Progress<IDownloadState>();
downloadProgress.ProgressChanged += (sender, e) =>
{
var progress = e.TotalByteCount > 0 ? 100.0 * e.BytesTransferred / e.TotalByteCount : 0;
};
var stream = await reference.GetStreamAsync(downloadProgress);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var cts = new CancellationTokenSource();
var task = Task.Run(async () =>
{
await Task.Delay(1000);
cts.Cancel();
});
var stream = await reference.GetStreamAsync(cancellationToken: cts.Token);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var url = await reference.GetDownloadUrlAsync();
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var metadata = await reference.GetMetadataAsync();
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
var metadata = new MetadataChange
{
ContentType = "image/jpeg",
CustomMetadata = new Dictionary<string, string>
{
["myCustomProperty"] = "myValue"
}
};
await reference.UpdateMetadataAsync(metadata);
var reference = CrossFirebaseStorage.Current.Instance.RootReference.Child("image.jpg");
await reference.DeleteAsync();
// All
var result = await CrossFirebaseStorage.Current.Instance.RootReference.ListAllAsync();
var items = result.Items.ToList();
// Pagination
var result1 = await CrossFirebaseStorage.Current.Instance.RootReference.ListAsync(10);
var token = result1.PageToken;
var result2 = await CrossFirebaseStorage.Current.Instance.RootReference.ListAsync(10, token);
var reference = CrossFirebaseStorage.Current.GetInstance("SecondAppName").RootReference.Child("image.jpg");
await reference.PutBytesAsync(bytes);