0

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?

  • An idea is to store details of the signed URL and upload status in the browser's local storage. – John Hanley Mar 24 '22 at 21:17
  • Yes, this is the way I implemented it for now and works fine. If there is no other way, I will stick with this solution, but I'm quietly hoping there's a better way - I would prefer to manage urls on backend site. Of course I can also use redis to cache urls on backend site, but maybe there is some cleaner way to resuse urls automatically :) – Nicolas Migut Mar 24 '22 at 21:27
  • The backend is not involved in the upload unless you make it involved and that just increases complexity and points of failure. Your JavaScript should record the upload state and then resume from that point on restart. Google Cloud Storage does not offer anything to assist you. I recommend keeping track of signed URLs and periodically performing housekeeping to remove uploads that were not completed. You will be charged for the temporary objects. – John Hanley Mar 24 '22 at 22:03

0 Answers0