File Upload using file input with Ionic (Selection

2019-05-03 11:19发布

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

1条回答
不美不萌又怎样
2楼-- · 2019-05-03 11:49

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.

查看更多
登录 后发表回答