如何将文件对象转换为URL

发布于 2025-02-04 18:39:15 字数 340 浏览 2 评论 0 原文

我有一个这样的javascript文件对象:

​我将如何通过JavaScript生成此文件的URL?

文件对象的JavaScript是这样的:

const file = new File(["blob data"], "foo.txt", {
  type: "image/png",

});

我想将此 file 变量传递到某个地方,并为其生成一个URL。有可能吗?

I have a javascript file object like so:

enter image description here

and I would like to turn it into a url so that the file can be accessed through the url. How would I go about generating a url for this file through javascript?

The javascript for the file object is something like this:

const file = new File(["blob data"], "foo.txt", {
  type: "image/png",

});

I would like to pass this file variable somewhere and have a url generated for it. Is that possible?

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

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

发布评论

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

评论(1

黎夕旧梦 2025-02-11 18:39:15

除非我误解了您的需求,否则这实际上是一个Google搜索我的朋友?

objecturl = url.CreateObjectUrl(Object);

This one was really one google search away my friend, unless I misunderstood your needs?

objectURL = URL.createObjectURL(object);

createObjectURL on Mozilla

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