获取使用的PhoneGap / JavaScript的一个文件的MIME类型类型、文件、PhoneGap、JavaScript

2023-09-06 11:37:40 作者:哭泣的过去

使用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.