Realm.LFS
1.0.0
See the version list below for details.
dotnet add package Realm.LFS --version 1.0.0
NuGet\Install-Package Realm.LFS -Version 1.0.0
<PackageReference Include="Realm.LFS" Version="1.0.0" />
paket add Realm.LFS --version 1.0.0
#r "nuget: Realm.LFS, 1.0.0"
// Install Realm.LFS as a Cake Addin #addin nuget:?package=Realm.LFS&version=1.0.0 // Install Realm.LFS as a Cake Tool #tool nuget:?package=Realm.LFS&version=1.0.0
Realm LFS
Realm LFS (large file storage) is an extension of the Realm.NET SDK that exposes an abstraction for interacting with binary files that are transparently uploaded to a 3rd party service (e.g. S3/Azure Blob Storage) and their URL is subsequently updated in the Realm object for other clients to consume.
Background
Using binary data (i.e. byte[]
properties) with Realm is supported but very inefficient. The recommended approach is to upload the data to a file hosting service and store just the URL in the Realm object, but doing so requires internet connection and defeats one of the main advantages of using Realm. The purpose of this library is to abstract as much as possible the uploading part and expose an interface that is as close as possible to the Realm API of interacting with data.
Usage
For the most part, just replace byte[]
properties with FileData
ones:
public class Recipe : RealmObject
{
public string Name { get; set; }
public string Summary { get; set; }
public IList<Ingredient> Ingredients { get; set; }
// Replace this
public byte[] Photo { get; set; }
// with this
public FileData Photo { get; set; }
}
To initialize the SDK, the minimum configuration you need to do is to configure the remote manager factory:
FileManager.Initialize(new FileManagerOptions
{
RemoteManagerFactory = (config) => new FunctionsFileManager(config, "MyDataFunction")
});
The FileData
class can be constructed from a Stream
- if you already have a byte[]
, that can be used to create a MemoryStream
.
When displaying an image from a FileData
, the code should look something like:
public void PopulateImage(Recipe recipe)
{
switch (recipe.Photo.Status)
{
case DataStatus.Local:
var imagePath = recipe.Photo.LocalUrl;
if (File.Exists(imagePath))
{
// we are the device that created the image - display it from disk
MyImage.ImageSource = new FileImageSource(imagePath);
}
else
{
// this image was created on another device, but it hasn't uploaded it yet
// to S3. Display a placeholder until the status changes to Remote
MyImage.ImageSource = placeHolderImage;
}
break;
case DataStatus.Remote:
MyImage.ImageSource = new ImageSource(recipe.Photo.Url);
break;
}
}
Customization
There are 3 supplied implementations of RemoteFileManager
, each shipped in a separate package:
Realm.LFS.Functions
provides a file manager that calls an Atlas Function to obtain a pre-signed url. Then it uploads data to the retried url.Realm.LFS.S3
uses the S3 SDK to upload files to an S3 bucket.Realm.LFS.Azure
uses the Azure SDK to upload files to Azure Blob Storage.
If you use another service or have your own web server that can process the file uploads, you need to supply your own implementation of RemoteFileManager
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Nito.AsyncEx.Context (>= 5.1.2)
- Realm (>= 11.1.2)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Realm.LFS:
Package | Downloads |
---|---|
Realm.LFS.S3
A RemoteStorageManager for Realm.LFS that uploads files to AWS S3. |
|
Realm.LFS.Azure
A RemoteStorageManager for Realm.LFS that uploads files to Azure blob storage. |
|
Realm.LFS.Functions
A RemoteStorageManager for Realm.LFS that calls an Atlas Function to obtain a pre-signed url for file uploads. |
GitHub repositories
This package is not used by any popular GitHub repositories.
## 1.0.0 (2023-07-24)
### Enhancements
* Updated to support Realm 10.x and newer.