Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File Upload using file input with Ionic (Selection of file using Native File Browser )

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

like image 432
Jeson Dias Avatar asked Nov 08 '22 11:11

Jeson Dias


1 Answers

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.

like image 126
Setu Kumar Basak Avatar answered Nov 14 '22 21:11

Setu Kumar Basak