xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

FileSaver API #1717

Closed DmitryBorodiy closed 1 year ago

DmitryBorodiy commented 3 years ago

Hello, Microsoft end .NET Xamarin Community! So, FilePicker API is cool, but Xamarin Forms need a FileSaver API for save files. Please implement this in Xamarin.Essentials.

Thanks! Best wishes!

davidortinau commented 3 years ago

How would this differ from System.IO and saving files? Essentials gives you the different storage path options in a nice xplat manner.

DmitryBorodiy commented 3 years ago

How would this differ from System.IO and saving files? Essentials gives you the different storage path options in a nice xplat manner.

This will work similarly to FilePicker, only it will not select files, but create and save.

DmitryBorodiy commented 3 years ago

This is should work like this.

FileSaver.Current.Properties.SuggestedFileName = "New file.txt";
var file = await FileSaver.SaveAndPickFileAsync(FileMode.ReadWrite);

if(file != null)
{
        //Do something with FileStream... 
}
dimonovdd commented 3 years ago

@davidortinau Hi I think it's talking about a similar 'SaveFileDialog' from WPF

DmitryBorodiy commented 3 years ago

@davidortinau Hi I think it's talking about a similar 'SaveFileDialog' from WPF

Yes!

DmitryBorodiy commented 3 years ago

@davidortinau Hi I think it's talking about a similar 'SaveFileDialog' from WPF

Or FileSavePicker on UWP.

dimonovdd commented 3 years ago

This issue has already been created. But I don't think it's possible

https://github.com/xamarin/Essentials/issues/1386

DmitryBorodiy commented 3 years ago

This issue has already been created. But I don't think it's possible

1386

Why?

DmitryBorodiy commented 3 years ago

FilePicker is implemented, but FileSaver not...

DmitryBorodiy commented 3 years ago

Creating own FileSaver dialog... It's slow and uncomfortable. But Xamarin.Essentials can resolve this problem if you add FileSaver API.

dimonovdd commented 3 years ago

Can you provide an sample of an application where this feature is made? This is non-standard behavior. You can use Share or Launcher.

On ios, the user can choose to save to files. I just recently fixed this feature.

On android, the user can choose a file manager that supports file saving.

If you want to save media files, it's better to use something like this

DmitryBorodiy commented 3 years ago

Can you provide an sample of an application where this feature is made? This is non-standard behavior. You can use Share or Launcher.

On ios, the user can choose to save to files. I just recently fixed this feature.

On android, the user can choose a file manager that supports file saving.

If you want to save media files, it's better to use something like this

So, In my Xamarin.Forms app I implement my own FileSavePicker for UWP and Android but it's not cross-platform...

DmitryBorodiy commented 3 years ago

Why FilePicker can't save files?

DmitryBorodiy commented 3 years ago

FilePickers - it's standart comfortable logic for open and save files...

dimonovdd commented 3 years ago

You may notice that many cross-platform applications support "Save As" function (Save File dialog) on macOS, Windows and Linux, but on mobile devices apps use an analog of Essentials.Launcher or Essentials.Share and save to Gallery/Photos functions for media files

DmitryBorodiy commented 3 years ago

But Android have DirectoryPicker and FilePicker intent... User can enter the file name in prompt dialog and select folder... The program can create and write file in this folder.

DmitryBorodiy commented 3 years ago

This is a Windows 10 Mobile user logic๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€

DmitryBorodiy commented 3 years ago

And it's more comfortable if you want write text files too

Jakar510 commented 3 years ago

For those that need it, FileSaver API. I also have helpers to share and use those files.

MuzzyA commented 2 years ago

For those that need it, FileSaver API. I also have helpers to share and use those files.

Link is no longer valid.

Still not seeing a FileSave dialog anywhere. Isn't there something? Even if it's UWP specific, that's fine by me. If FilePicker exists, it's a very small change to make it a FileSaver as well. It's just returning a directory and a file name.

The FilePicker can only be used as a 'FileSaver' if the file already exists. But, you need to be able to specify a new file.

Jakar510 commented 1 year ago

For those that need it, FileSaver API. I also have helpers to share and use those files.

Link is no longer valid.

Still not seeing a FileSave dialog anywhere. Isn't there something? Even if it's UWP specific, that's fine by me. If FilePicker exists, it's a very small change to make it a FileSaver as well. It's just returning a directory and a file name.

The FilePicker can only be used as a 'FileSaver' if the file already exists. But, you need to be able to specify a new file.

Here's the updated link

jfversluis commented 1 year ago

I think at this point it's safe to say that this won't be making it's way into Xamarin.Essentials anymore. Keep your eye on .NET MAUI for all new development! Thanks for all input and efforts here.

Also, this one is now available in the .NET MAUI Community Toolkit!