CommunityToolkit.Maui.Storage.FileSaver on iOS strange

Eigil Krogh Sorensen 76 Reputation points
2023-03-26T16:35:16.08+00:00

I have the latest release version of CommunityToolkit.Maui (5.0.0).

When I run CommunityToolkit.Maui.Storage.FileSaver in my app on iOS I get a strange user interaction. The window shown looks like that in the iOS_FileSaver.png image attached. The filename is a GUID number. The fileName string I enter in SaveAsync has no influence at all.

iOS_FileSaver

If however I run the git@github.com:CommunityToolkit/Maui.git/ essentials / FileSaver using static FileSaver on iOS the I get the result in the attached CommunityToolkit.Maui.png ImageCommunityToolkit.Maui

I can't find out why that is. My code looks very much like the code in git@github.com:CommunityToolkit/Maui.git/ essentials / FileSaver using static FileSaver example. My code:

	public async Task<FileSaverResult> SaveToTextFile(MemoryStream TheStream, string filename)
	{
		try
		{
			return await FileSaver.Default.SaveAsync("/", "Test.txt", TheStream, default);
		}
		catch (Exception e)
		{
			var msg = $"File is not saved, {e.ToString()}";
			await Shell.Current.DisplayAlert("Error", msg, "OK");
			System.Diagnostics.Debug.WriteLine("SaveToTextFile failed: {0}", e.ToString());
			return null;
		}
		finally
		{
		}
	}

git@github.com:CommunityToolkit/Maui.git/ essentials / FileSaver using static FileSaver example code:

	[RelayCommand]
	async Task SaveFileStatic(CancellationToken cancellationToken)
	{
		using var stream = new MemoryStream(Encoding.Default.GetBytes("Hello from the Community Toolkit!"));
		var fileSaveResult = await FileSaver.SaveAsync("DCIM", "test.txt", stream, cancellationToken);
		if (fileSaveResult.IsSuccessful)
		{
			await Toast.Make($"File is saved: {fileSaveResult.FilePath}").Show(cancellationToken);
		}
		else
		{
			await Toast.Make($"File is not saved, {fileSaveResult.Exception.Message}").Show(cancellationToken);
		}
	}

What is the difference ? I very much prefer the git@github.com:CommunityToolkit/Maui.git/ essentials / FileSaver using static FileSaver example version.

-

Eigil

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,866 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,316 Reputation points Microsoft Vendor
    2023-03-28T01:48:20.1633333+00:00

    Hello,

    There is a known issue reported at ToolKit's GitHub Repo: [BUG] FileSaver on Mac - new GUID used for name instead of name provided #1059

    It has been fixed but not released, you can follow the progress at GitHub.

    So, as you @Eigil Krogh Sorensen said, you can make NuGet package from the source, which is a good option.

    Thanks for your sharing.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Eigil Krogh Sorensen 76 Reputation points
    2023-03-27T13:57:31.7533333+00:00

    Cloned git@github.com:CommunityToolkit/Maui.git and made nuget pkgs from the source.'

    Now it is working on iOS/iPadOS in my app !