1

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

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.

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?

2 Answers 2

3

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 would be your mime type.

Sign up to request clarification or add additional context in comments.

Comments

1
    function getType(file_URI) {
        window.resolveLocalFileSystemURI(file_URI, function(fileEntry) {
            fileEntry.file(function(filee) {
                alert(filee.type); //THIS IS MIME TYPE
            }, function() {
                alert('error getting MIME type');
            });

        }, onError);
    }

2 Comments

resolveLocalFileSystemURL doesnot for content URI like this content://com.android.providers.media.documents/document/image%3A2119 . If you have any work around to find out the mime type of file using above url please suggest me.
Subscribing to above comment, on iOS the filee.type exists but is null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.