[Cloud Storage] Error when uploading an empty file.
szgupta opened this issue · 1 comments
Hi there! I was using the cloud storage API to upload an empty file to GCS and got the following error:
HTTP status client error (411 Length Required) for url (https://storage.googleapis.com/upload/storage/v1/b/bucket-name/o?uploadType=media&name=hello_world.txt)
I was able to get around it by explicitly setting the Media::content_length
property to Some(0)
when the data was empty.
I couldn't track it down in GCP docs, but is it known that the content-length header must be set (with a value of 0) if uploading an empty file? And if so, should this be implemented within the cloud-storage crate (i.e. at the library level)?
Since the library for Golang is able to upload even 0 bytes without explicitly specifying content-length, we think it would be better to automatically set content-length: 0 inside the library.
After investigation, it seems that we can get the size of the body with zero-copy, so we will implement it.