如何缓存签名的url以存储特定路径?

发布于 2025-01-16 21:55:28 字数 479 浏览 2 评论 0原文

我正在使用签名的 url 生成会话 uri,以便可恢复上传到 gcp 存储桶。流程如下:

  1. 客户端向后端发出请求,后端生成用于 post 请求的签名 url,用于启动断点续传会话
  2. 后端生成签名 url 并将其返回给客户端
  3. 客户端向该 url 发送 post 请求以启动断点续传会话
  4. 客户端收到会话 uri 作为响应,并开始以多个块上传大文件(对会话 uri 执行多个放置请求)

现在问题如下:在上传期间,客户端刷新页面并尝试再次上传文件。它应该从最后一个持久化的块开始,但是当刷新客户端再次询问后端有关签名的 url 时,后端正在生成新的签名的 url,因此上传从头开始。

有没有办法自动缓存签名的网址,因此对于后端站点上的 emaple,当执行存储中特定路径的请求时,我可以重新使用以前的签名网址(只要它仍然有效)?当然我可以手动缓存它,但我想知道是否有办法自动执行?例如,存储中的特定路径始终只有一个有效的签名 URL?

I'm using signed url to generate session uri for resumable upload to gcp storage bucket. The flow is following

  1. client performs request to the backend, which generates signed url for post request, which is meant to be used to start resumable upload session
  2. backend generates signed url and returns it to client
  3. client sends post request to the url to start resumable upload session
  4. client receives session uri in response and starts uploading large file in multiple chunks (performs multiple put requests to the session uri)

Now the problem is following: during upload client refreshes page and tries to upload a file again. It should start from the last persisted chunk, but as after refresh client asks again backend about signed url, new signed url is being generated by backend, so upload starts from the beggining.

Is there any way to automatically cache signed urls, so for exmaple on backend site, when request for specific path in storage is being performed, I can resuse previous signed url (as long as it's still valid)? Of course I can cache it manually, but I am wondering if there is a way to do it automatically? For example to have always only one valid signed url for specific path in storage?

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

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

发布评论

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