获取使用的PhoneGap / JavaScript的一个文件的MIME类型 [英] Getting a file mime type using PhoneGap/JavaScript

查看:99
本文介绍了获取使用的PhoneGap / JavaScript的一个文件的MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PhoneGap的是有可能得到的文件在本地文件系统中的MIME类型?

Using PhoneGap is it possible to get the mime type of a file in the local file system?

我的应用程序的一部分下载从我们的服务器上的远程URL文件并将其保存到Android的下载文件夹中。然后我用WebIntent插件来打开该文件,但这些都需要一个选项是MIME类型。

Part of my app downloads a file from a remote URL on our server and saves it to the Android downloads folder. I then use the WebIntent plugin to open the file but one of the options this requires is a mime type.

我已经无法找到API文档任何东西,或比谷歌的这里,但是这是更相关的表格。

I've not been able to find anything in API Documentation or Google other than here, but that is more relevant to forms.

有没有人尝试过​​这样做吗?

Has anyone tried to do this before?

推荐答案

像这样的事情在Android上,但情况因人而异会工作在其它平台上:

Something like this would work on Android but YMMV on other platforms:

var medFile = new MediaFile("empty.txt", "file:///mnt/sdcard/empty.txt");
console.log("file path = " + medFile.fullPath);
medFile.getFormatData(function(metadata) {
    console.log("mimeType = " + metadata.type);
}, function() {
    console.log("fail");
});

metadata.type将是你的MIME类型。

metadata.type would be your mime type.

这篇关于获取使用的PhoneGap / JavaScript的一个文件的MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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