Search code examples
nativescriptangular2-nativescriptfilepicker

How to let user pick file for upload in nativescript (tried nativescript-imagepicker but need also non-images)


I'm trying to let user pick a file (from storage) inside my NativeScript app to later upload that file to a server, but I couldn't find any file-picker really working.

I've found out that someway it should be possible to use nativescript-imagepicker for selecting any file type and get file path from there for upload. This would be great cause I could then use Nativescript-Filesystem for my purpose. I create context this way:

let context = imagepicker.create({
            maximumNumberOfSelection: 1,
            minimumNumberOfSelection: 1,
            mediaType: imagepicker.ImagePickerMediaType.Any,
            mode: 'single'
          });

However I cannot select any file other than images on android (API 28) and from documentation "mediaType" is only for iOS. Has anyone been able to make it work this way as reported in first link? Am I missing something?

Is there any other way I could try to accomplish my desired result? I've had a try also on Mediafilepicker but cannot use it because it gives me a lot of conflicts with existing plugins I need for my project. Just need something simple for selecting a file, what's the best "NativeScript way" of doing this? (preferably working both on android and iOS)

Please let me know if you need other info and be patient, I'm kinda noob on NativeScript. Thank you in advance.


Solution

  • Media File Picker is one good option, let's know what conflicts you are facing there.

    If you prefer to do it on your own then you might need little bit knowledge on marshalling Objective C & Java. With Android, it's quite easy to throw an Intent to pick any or specific type of files for you. With iOS you will have to use UIDocumentPickerViewController to pick up the file.