MAUI Android Why Image is not saved?

136 views Asked by At

I try to save a image locally using my MAUI app on Android. The test if (File.Exists(filePath)) is positive. But when I search for this file using a total commander on Android or using the file explorer on Windows I can't find the file.

The value of filepath is:

/data/user/0/de.company.appname.beta/files/0001/UserProfileImage.png

Using the Windows Explorer searching for "de.company.appname.beta" I find a path like this:

Dieser PC\Franks Galaxy A33 5G\SD-Karte\Android\data\de.company.appname.beta

but in this folder I find only a folder "cache", but not "files".

Searching for the file name "UserProfileImage.png" has no results.

The string filePath I'm passing to a SfAvatarView. There is not the right image visible. (Which is why I am looking for the problem when saving the image.) On Windows it works, not on Android.

Why can't I save the image locally?

try
{
    await File.WriteAllBytesAsync(_personDto.Image, Convert.FromBase64String(cleanPath));
}

No exception is thrown.

1

There are 1 answers

0
H.A.H. On BEST ANSWER

I do not know "SfAvatarView" but I doubt it will be too far away from Image.

And for sources for ImageView, android likes to cache files. Using file name, of course. And judging by your fixed file name, I can say that it is happening.

I had two options to solve this:

First option is to keep changing the file name, so it does not cache itself. Second option is to clear the cache directory.

I went for the second option:

Enumerate all files in this directory:

Path.Combine(FileSystem.CacheDirectory, "image_manager_disk_cache");

And execute deletion.

Lately, there have been other solutions: https://github.com/dotnet/maui/issues/9773