且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

BLOB URL 的自定义名称

更新时间:2023-09-01 15:36:46

简短的回答,你不能.

这是一个指向浏览器内存的地址,它存储了您的 blob,或者在用户通过输入 type=file 上传文件的情况下指向原始文件的指针.

This is an address that points to the browser's memory, where it has stored your blob, or a pointer to the original file in case of user uploaded file through the input type=file.

不知何故,这是设计使然.您可以从同一个 Blob 创建多个这些 blobURL.如果他们使用文件名作为 URI,你就不能.

This is somehow by design. You can create multiple of these blobURLs from the same Blob. If they were to use a filename as URI, you couldn't.

理论上,您应该可以动态创建一个重定向到 BlobURI 的页面,并且您可以将这个重定向页面命名为您的 which.但这只是理论,我自己从未尝试过.

Theoretically, it should be possible for you to dynamically create a page that would redirect to the BlobURI, and you could name this redirection page as you which. But this is just theory, I never tried to do it myself.

一个粗略的概念证明可以在 这个 plunker 中看到,显然,你'需要动态生成 blobRename.html,并将其名称更改为您想要的名称,并强制它是内容标题,以便浏览器认为它是一个 html 页面,如果您想摆脱.html.另请注意,它似乎不适用于需要浏览器插件才能触发的 pdf 文件,但如果再做一些工作,可能就可以破解一些东西.

A rough proof of concept can be seen in this plunker, obviously, you'll need to generate blobRename.html dynamically, and change its name to the one you want, and also force it's content-header so that the browser thinks it's an html page if you want to get rid of the .html. Also note that it doesn't seem to work with pdf files, which need browser plugins to trigger in, but with some more work, it may be possible to hack something around.

但无论如何,我只会让随机 url,随着越来越多的网络应用程序确实使用这个伟大的 API,您的用户会越来越习惯它.

But anyway, I would just let the random url, your users will get more and more used to it as more and more web apps do use this great API.