如何使用JavaScript查找MIME类型的IPF(未给出的扩展名)?

发布于 2025-01-24 18:59:59 字数 563 浏览 6 评论 0原文

如果我有一个IPFS CID地址(没有扩展),则 这样的文件为实例https://ipfs.infura.io/ipfs/qmnhq4hx1kftw1a5ptttudgxm9q4xhwdeuwtpssg19sssseu,我如何找到使用Javascript的Mime类型?

我已经尝试了以下操作:

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

这总是给我未定义的。 任何帮助都将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2025-01-31 18:59:59

您有一个URL,因此要获得MIME类型,您可以提出HTTP Head请求。

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

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'));
})()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文