6.1 C
Canberra
Monday, October 27, 2025

ios – .web MAUI deal with photos from API


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);

}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles