pistolpete
pistolpete

Reputation: 998

Upload zero size final part to Google Cloud Storage resumable upload

A common problem when using resumable upload's is that the final size of the upload is not known when it is started. Google has solved this problem through allowing the user to (credit to this SO answer):

(a) send a chunk that is not a multiple of 256kB (the required chunk size of GCS), or

(b) sending a chunk with bytes NNN-MMM/(MMM+1). That is, the last chunk contains the total size for the upload and indicates that it contains the last byte

The problem I am having is with the edge case of sending the last chunk that is a multiple of 256kB and not knowing it is the last chunk until after it has already been sent to the GCS API. I thought I would be able to get around this by sending a zero byte chunk with headers of Content-Length: 0 and Content-Range: NNN-MMM/(MMM+1), e.g (Content-Range: 262143-262143/262144). This does not appear to work though, and I get a 408 timeout response and the object is not finalized.

What can I do to solve this problem and tell the GCS API that my upload is finished after I have already uploaded all the data?

Upvotes: 1

Views: 478

Answers (1)

Soni Sol
Soni Sol

Reputation: 2612

The issue with a packet of length 0 at the end is a known issue which is being tracked on This Github Channel It is still an open issue.

The issue seems to be that the server treats it as a 0 byte upload and returns that the previous chunks were uploaded but the client continues waiting for the confirmation of the last chunk.

As a work around you can be reading for the current chunk and following chunk, and when detect that following chunk length is 0 you can divide current chunk in two chunks.

Upvotes: 1

Related Questions