使用Ionic的文件输入进行文件上传(使用本机文件浏览器选择文件) [英] File Upload using file input with Ionic (Selection of file using Native File Browser )

查看:2206
本文介绍了使用Ionic的文件输入进行文件上传(使用本机文件浏览器选择文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的离子应用程序标记中,我有

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);

当我上传图片或视频时这很有效。如果使用下图中的文件管理器选项。但是我从快速链接列表上传音频时遇到问题,或者使用第三方浏览器获取文件。在大多数情况下,返回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 .

但我遇到两个问题

1)当我使用侧边栏上的快速链接上传一个音频文件时,列出所有音频文件及其名称。点击文件来回在这个列表中我没有得到我需要的文件对象中的扩展名和内容类型。但是,如果我使用文件管理器选项并导航到该文件,则同样有效。它几乎就像音频快速链接列表只有很少的细节,没有扩展或内容类型的细节。

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 .

2)如果我使用第三个 - 如同ES浏览器的派对浏览器或应用程序崩溃并停止的图像侧边栏中显示的音乐应用程序。

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 .

那么还有其他方法可以导航到从应用程序上传的文件,或者我做错了什么。 ImagePicker cordova插件。只是选择图像的限制是问题,否则就会使用

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

推荐答案

Android不提供原始文件名和文件类型使用上面的认可它是android的安全问题。因此,我必须在下面的解决方案中检索正确的文件名,文件类型,文件大小和base64中的文件数据。

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.

这篇关于使用Ionic的文件输入进行文件上传(使用本机文件浏览器选择文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆