5

In my ionic app markup i have

<input type="file" id="file" />

in my controller i am getting the file on selection from file manager

 fileinput.addEventListener('change', function (event) {
        var file = event.target.files[0];
        console.log(file);

This works well when i upload images or videos .and also if use the file manager option from the image below . but i encounter problems when uploading audio from quick links list or if use third party browser to get the file. in most other case the File object is returned and i can upload it successfully .

enter image description here

but i am encountering two problems

1) when i use the quick links on the sidebar to upload an audio file which lists all audio files with their names .On clicking a file from this list i do not get the extension nor the content-type in the file object which i need . But the same works if i use the file manager options and navigate to the file . it's almost as if the audio quick link list just has few details and does not have extension or content-type details .

enter image description here

2) If i use the third -party explorer like ES explorer or the music app shown in sidebar of the image the App crashes and stops .

So is there any other way to navigate to a file to upload from the app or am i doing something wrong . ImagePicker cordova plugin's . limitation of just choosing images is the problem or else would have used that

Jeson Dias
  • 883
  • 2
  • 11
  • 26
  • I am facing the same issue . do you find answer to that – sam Feb 03 '17 at 10:56
  • @sam yes i used https://github.com/don/cordova-filechooser . this worked fine .. returned me the native path ..which i could convert later – Jeson Dias Feb 07 '17 at 11:02
  • 1
    I used the same plugin and resolved it later with `cordovafilepath` plugin. Thanks man – sam Feb 07 '17 at 11:08
  • check the sd card permission. This happens due to permission not granted to sd card. – Sutirth Feb 08 '17 at 07:18
  • Is there any workaround by using html input? I don't want to use the cordova-filechooser plugin. Is there any way without using the plugin? I am not getting the content type when i am trying to upload a pdf file. I need for both iOS and Android – Setu Kumar Basak Apr 08 '18 at 11:05
  • @SetuBasak Don't think so . Since the cordova-filechooser is like an interface over the phone's native way of choosing a file for upload . (and doing things like opening file manager ) . This was a while back though . You can try if modern webviews can comprehend that . – Jeson Dias Apr 10 '18 at 04:33

1 Answers1

1

Android does not give the original file name and file type using the above approachand it is a security issue from android. So, i had to make below solution for retrieving the correct file name, file type, file size and the file data in base64.

You can follow my solution here.

Setu Kumar Basak
  • 11,460
  • 9
  • 53
  • 85