question

Barto avatar image
0 Votes"
Barto asked JarvanZhang-MSFT edited

CachedImage - Access the downloaded file

I am using the CachedImage component of ffimageloading. I have a kind of gallery with a carousel view.

All the images are loaded through an internet URL, they are not local images. I would like to add the image sharing function. But I don't want to download the file again, I would like to know if there is a way to access the file that the CachedImage component already downloaded to be able to reuse it in the share function.

dotnet-xamarinformsdotnet-xamarinessentials
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JarvanZhang-MSFT avatar image
1 Vote"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

Hi, Barto. To get the cached image, try using the MD5Helper.

var filepath = ImageService.Instance.MD5Helper.MD5("the file url");

Refer to: https://github.com/luberda-molinet/FFImageLoading/issues/1214#issuecomment-472073935

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Barto avatar image
0 Votes"
Barto answered JarvanZhang-MSFT commented

Thanks @JarvanZhang-MSFT

I share with you how part of my code is:

    var key = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey");
    var imagePath = await ImageService.Instance.Config.DiskCache.GetFilePathAsync(key);
    var tempFile = Path.Combine(Path.GetTempPath(), "test.jpg");
    if (File.Exists(tempFile))
    {
        File.Delete(tempFile);
    }
    File.Copy(imagePath, tempFile);
    
    await Share.RequestAsync(new ShareFileRequest
    {
        Title = "Test",
        File = new ShareFile(tempFile)
    });

The temporary file I believe, since the cached file has no extension and the applications do not recognize the type.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The temporary file I believe, since the cached file has no extension and the applications do not recognize the type.

Try to create a file via the cached image's path to check if the file is null. If it's not null, then try to share the file using the cached file path directly.

//1.
var key = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey");
var imagePath = await ImageService.Instance.Config.DiskCache.GetFilePathAsync(key);

FileStream fs = File.Create(path);
//check if the fs is null

//2.
await Share.RequestAsync(new ShareFileRequest
{
    Title = "Test",
    File = new ShareFile(imagePath)
});
0 Votes 0 ·
Barto avatar image Barto JarvanZhang-MSFT ·

I tried it that way. But no matter how much you specify the type of content (example new ShareFile(imagePath, "image/png")), some applications (example whatapp) did not recognize it, since they verify by the extension of the file and not by the type of content. So I had to create a temporary file with the corresponding extension.

I show you the example in whatsapp of what happens if I directly shared the cache file:
83256-image.png



1 Vote 1 ·
image.png (189.3 KiB)

Thanks for sharing the info about this.

0 Votes 0 ·