1

If I have an IPFS CID address (with no extension), of a file like this for instance https://ipfs.infura.io/ipfs/QmNhq4hx1KfTw1a5pTtudGXm9Q4xhWdeuWtPSSG19SSZeU , how can I find its MIME type using Javascript?

I've tried the following:

let file='https://ipfs.infura.io/ipfs/QmNhq4hx1KfTw1a5pTtudGXm9Q4xhWdeuWtPSSG19SSZeU'
if (window.FileReader && window.Blob) {
    console.log("All the File APIs are supported by the browser.");
    console.log("Type: " + file.type);
} else {
    console.log("File and Blob are not supported by the browser");
}

This is always giving me undefined. Any help would be much appreciated.

1

1 Answer 1

1

You have a url, so to get the mime type you can make a HTTP HEAD request.

(async function(){ 
let file='https://ipfs.infura.io/ipfs/QmNhq4hx1KfTw1a5pTtudGXm9Q4xhWdeuWtPSSG19SSZeU';
var req = await fetch(file, {method:'HEAD'});
console.log(req.headers.get('content-type'));
})()

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

1 Comment

Not got mime type after passing { mode: 'no-cors' } on place of {method:'HEAD'}.

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.