We’re engaged on an utility that receives enormous quantities of information from the backend. This additionally incorporates a listing of photos, and the format of the picture response is at all times base64 string photos. This can’t be modified.
Within the first model, we transformed it to a byte array, and the ImageSource transformed it to a picture, however this has actually dangerous efficiency, and the applying shall be very sluggish if a number of photos are added.
so we determined to avoid wasting the photographs domestically on the gadget in a background job and if this native path is offered, the ImageSource will use the trail, fallback is the byte ImageSource.
the query is that if this can be a good resolution to avoid wasting the information domestically:
non-public async Process LoadImagesToLocalStorage(Guid activityId, Attachment attachment)
{
var title = attachment.Title;
var splits = attachment.Title.Cut up("Library/");
if (splits.Size > 1)
{
title = splits[1];
}
if (!string.IsNullOrWhiteSpace(title) && File.Exists(title))
{
return;
}
// Make sure the listing exists
var cacheDir = FileSystem.Present.AppDataDirectory;
var localFilePath = Path.Mix(cacheDir, title);
if (File.Exists(localFilePath))
{
attachment.LocalPath = localFilePath;
}
else
{
strive
{
// create stream from byte array
utilizing MemoryStream sourceStream = new MemoryStream(attachment.Knowledge);
await utilizing FileStream localFileStream = File.Open(localFilePath, FileMode.OpenOrCreate);
await sourceStream.CopyToAsync(localFileStream);
attachment.LocalPath = localFilePath;
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
return;
}
}
await _attachmentDatabase.SaveAttachment(activityId, attachment, CancellationToken.None)
.ConfigureAwait(false);
}
