是否可以将文件存储在浏览器的临时文件夹中并使用JavaScript检索它们?

发布于 2025-01-31 08:33:43 字数 669 浏览 2 评论 0原文

我在前端上使用PDF查看器,该查看器只能读取.pdf url(它无法直接读取blob)。因此,我需要首先将这些文件下载到用户的计算机上。假设这是我想做的:

// download blob
let pdf = fetch(mysite.com);

// store in a temporary folder
// maybe "%AppData%\Local\Google\Chrome\User Data\Default\Cache"?
browser.storeFile(pdf);

// retrieve the file from temporary folder and pass to PDF viewer
myPDFViewer.load('%AppData%\Local\Google\Chrome\User Data\Default\Cache\my-file.pdf')

我正在使用的PDF查看器可以完全加载离线文件,只要我拥有文件的绝对路径(以.pdf结束)。我已经尝试了各种各样的事情,但仍然无法从获取的斑点生成此类.pdf url。

因此,是否可以下载文件,将文件存储在浏览器内部的临时文件夹中(该文件将自动清理),并为这些文件生成绝对的本地路径吗?

I'm using a PDF viewer on the frontend which can only read .pdf URLs (it's not able to read blob directly). So I'll need to download those files to the user's computer first. Hypothetically, this is what I want to do:

// download blob
let pdf = fetch(mysite.com);

// store in a temporary folder
// maybe "%AppData%\Local\Google\Chrome\User Data\Default\Cache"?
browser.storeFile(pdf);

// retrieve the file from temporary folder and pass to PDF viewer
myPDFViewer.load('%AppData%\Local\Google\Chrome\User Data\Default\Cache\my-file.pdf')

The PDF viewer I'm using can load offline files perfectly fine, as long as I have the absolute path to the file (ending with .pdf). I have tried all sorts of things but still not able to generate such .pdf URLs from the fetched blob.

So, is it possible to download files, store them in a temporary folder internal to the browser (which will get cleaned up automatically), and generate absolute local paths to those files?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文