CommunityToolkit.Maui.Storage.FileSaver on iOS strange

Eigil Krogh Sorensen 96 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 ******@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 ******@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
		{
		}
	}

******@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 ******@github.com:CommunityToolkit/Maui.git/ essentials / FileSaver using static FileSaver example version.

-

Eigil

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    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 96 Reputation points
    2023-03-27T13:57:31.7533333+00:00

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

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.