Essentials: Proposal : FilePicker / FolderPicker

Created on 13 May 2018  路  18Comments  路  Source: xamarin/Essentials

Description
FilePicker / FolderPicker : nice if you add this feature
thanks

VS bug #735675

feature-request needs-more-discussion proposal

Most helpful comment

Yes, I believe this is feature actually spans multiple potential features that uses files such as camera, email, file picker, etc and all make use of a File Provider on Android and a cross-platform File in some way.

This one is higher up on our list to integrate, but these other points need to go into API design first.

All 18 comments

This will probably use ActionGetContent Intent on Android and UIDocumentPickerViewController on iOS and FileOpenPicker on UWP

Already implemented at Studyxnet/FilePicker-Plugin-for-Xamarin-and-Windows but has been abandoned.

Edit:

So the more I work with this feature the more I find out that it is not that simple on iOS. There are 3/4 classes to work with when implementing this feature.

  • UIDocumentPickerViewController Can access iCloud documents and some app files but I can't seem to access anything from the gallery.
  • UIImagePickerController Allows access to gallery Images and Videos when the SourceType is set to PhotoLibrary. Can also be used to prompt the user to take a photo with the camera by setting the SourceType to Camera.
  • UIDocumentBrowserViewController I haven't worked with this one yet but it seems to allow you to access to everything and also includes editing/deleting/creating files and folders and allows multiple selection.
  • UIDocumentMenuViewController which is deprecated and UIDocumentPickerViewControllershould be used instead according to Apple Docs.

Since this feature seems to be forgotten so I suggest the following API which is exactly the API of jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows a better "fork" of Studyxnet/FilePicker-Plugin-for-Xamarin-and-Windows :

FilePicker Class

public static classFilePicker
{
    //This returns a long running task which can be awaited for as long as the picker interface is visible. AllowedTypes are optional and defaults to * (all) if not provided.
    Task<FileData> PickFile (string[] allowedTypes = null);
    //Save the file to 
    //Android.OS.Environment.ExternalStorageDirectory on Android,
    //Environment.SpecialFolder.MyDocuments on iOS and
    //ApplicationData.Current.LocalFolder on UWP
    Task<bool> SaveFile (FileData fileToSave);
    //Opens the file using the appropriate document viewer on each platform
    void OpenFile (string fileToOpen);
    //Same as above but takes a FileData class
    void OpenFile (FileData fileToOpen);
}

FileData Class

public class FileData : IDisposable
{
    public FileData();
    public FileData(string filePath, string fileName, Func<Stream> streamGetter, Action<bool> dispose = null);

    public byte[] DataArray { get; }
    public string FileName{ get; set; }
    public string FilePath { get; set; }

    public Stream GetStream()
    public void Dispose()
}

I think that SaveFile and OpenFiles are irrelevant here since this is a file picker and it should do one thing and that is picking files. For the implementation, it is already done on @jfversluis's repo. I can try and move the code to this repo in my free time but I really have no prior experience with it. Still I will try and report back if things go well.

That would actually be a great idea. I am trying my best to uphold the Filepicker plugin, but it seems I can't keep up with what is demanded from it. Incorporating it in the Essentials library would be a great addition. I can help out @AmrAlSayed0 but let's wait and see what thoughts are about this move

Yes, I believe this is feature actually spans multiple potential features that uses files such as camera, email, file picker, etc and all make use of a File Provider on Android and a cross-platform File in some way.

This one is higher up on our list to integrate, but these other points need to go into API design first.

Hi, I'm one of the maintainers of @jfversluis' fork of the original Studyxnet's FilePicker plugin (this one: https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows). We currently have a stable plugin, with no pending issues currently being reported.

What would be the next steps for me to work on porting the plugin to Xamarin.Essentials? Just do a PR?

I also have some questions:

  • There are no xml comments in Xamarin.Essentials code - is it on purpose? Should I delete all xml code comments when porting the plugin?
  • How do I generate the xml doc files that are in the docs folder?

@mattleibow @Redth @jamesmontemagno anyone could answer my questions? Thanks!

Hi @vividos , about the docs, this can help you.

https://github.com/xamarin/Essentials/wiki/Documenting-your-code-with-mdoc

Sorry about the delay, for some reason I missed your last comment.

Looking through the issue, I agree with @AmrAlSayed0 about the opening parts being left out - we can actually do that with the Launcher if I am not mistaken. (which is in your obsolete messages) We don't support popping up things from random streams, but we could add that overload.

With regards to letting files out of the app - like share or open other apps - we have a PR that we are working on #416. That will allow us to expose files to the world - just like when you copy it to external storage. Our current work tries to be clever and only copy it if it needs to (and tries to find the best place to copy to)

For docs, @pictos is correct. That wiki should explain things somewhat, but the short of it is write the API first, and once it is done, we run the task and it pops out docs for you to populate.

And finally, and most importantly, the code :) Yup! Just do a PR! All you need to do is create a folder and start working in there.

@jamesmontemagno @Redth we really need to get #416 looked at and reviewed. It is holding up several features - email, file sharing, sms and anything that needs to expose something inside the app to the world (or other apps).

For those writing code, you can either start with the other platforms and start forming the API so that we can iterate and review. Or, you could start from the feature/android-file-provider branch and use those features. That will allow you to get all the platforms working nicely, but you just need to be aware that we may need to change the APIs if we spot something wrong with our current implementation. I don't foresee much changing, but it might.

Another thing to be aware of since this is working with files/data, is that we have implementations of "file objects" in various PRs - the attachment object in #416 and the media file in #613. Right now, those PR are still open, so you can't really use it, but just go ahead and create a new type 馃槈 Once we see the requirements for this to work, we can have a look merging all of these together. Chances are, these things will be very similar, but just make sure you have all that you need in your version of the file, and we can discuss. I created a new issue (https://github.com/xamarin/Essentials/issues/685) to track this.

I'm working on learning to TLS secure my mqtt xamForms applications in a real world way for the various platforms.

It occurred to me that an X509Certificate file picker ?and placer? might be handy in xamarin essentials.

Until the file picker is added to essentials, you can use jfversluis' FilePicker plugin, it works great!

It should also have the ability to show available service and pick files from them, e.g. Google Drive, Apple Files, DropBox,, etc if installed on device

On Android this is already the case; Google Drive and OneDrive offer the files stored online, and surely the other services also. On iOS it's iCloud and OneDrive, maybe others, too.

Any news on this. LOB apps really need this essential control the FilePicker, to get external files from disk.
I.e. upload a .pdf ..not just images.

The Xamarin folks don't react to my messages, sadly. In the meantime you can use this plugin, on which this PR is based on: https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows

This is needed especially when using with ShareFile +1

I see some progress on the dev/file-picker branch. Is this still being worked on? Could this feature use another contributor? Is there a target date for 1.6?

Was this page helpful?
0 / 5 - 0 ratings