Xamarin - CachedImage - Access the downloaded file

145 Views Asked by At

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.

2

There are 2 best solutions below

0
Jason On

try using MD5Helper

var path = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey")'
0
Barto On

Thanks Jason

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.