1

I'm trying to upload image file to Google Cloud Storage with pre-signed URL (Spring boot). The file got uploaded but the object metadata also written in the file. Because of that it is loading as corrupted data.

How to remove that Object metadata from the file while upload/download the file from Google Cloud Storage?

String preSignedURL = gcpStorageService.signUrl(BlobInfo.newBuilder(gcpProperties.getBucketName(), blobName).build(), 5, TimeUnit.MINUTES,
            SignUrlOption.httpMethod(HttpMethod.PUT)).toString();

When I call the presignedURL, the file got uploaded. But the uploaded object contains metadata as well.

For Example: I uploaded text file with text "google cloud storage test". When I download it, it looks like

------WebKitFormBoundaryqCsAsznB1hGFXICd
Content-Disposition: form-data; name="Expires"

1564396735
------WebKitFormBoundaryqCsAsznB1hGFXICd
Content-Disposition: form-data; name="Signature"

------WebKitFormBoundaryqCsAsznB1hGFXICd
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

google cloud storage test
------WebKitFormBoundaryqCsAsznB1hGFXICd--

Thanks in advance

  • could you please show the code what you have tried till now? – Pallamolla Sai Jul 29 '19 at 12:48
  • You can remove an object's metadata as detailed by the [gsutil setmeta command](https://cloud.google.com/storage/docs/gsutil/commands/setmeta). Since some of the metadata is [fixed-key metadata](https://cloud.google.com/storage/docs/metadata#editable) whose keys are set, but for which you can specify a value, it is unclear if keeping the value empty would resolve your issue. It is also unexpected that uploading via Cloud Storage pre-signed URL would result in a corrupt file due to metadata. Can you specify the format of the file as it seems there may be issues with the file being uploaded. – Julie Wang Jul 29 '19 at 15:38
  • The software that uploaded the file to Cloud Storage is broken. Object Metadata is NOT being written to the object. This is an HTTP file upload problem in your code. What you are seeing is the "boundary" between chunks of file data being uploaded. Somehow this is corrupt, so Cloud Storage is just seeing the stream as object data. – John Hanley Jul 30 '19 at 05:53
  • I am uploading the file using Postman. – Manikandan S Jul 30 '19 at 06:31
  • can you please try once 'Content-Type': 'multipart/form-data'? – Pallamolla Sai Jul 30 '19 at 06:40
  • Same response with 'Content-Type': 'multipart/form-data' as well – Manikandan S Jul 30 '19 at 07:38
  • Can you provide your code? It does seem like the Content-type may be incorrect (perhaps "media"? instead) but it is unclear. This [stackoverflow post](https://stackoverflow.com/questions/27924389/google-cloud-storage-uploaded-image-is-corrupt) is of a similar issue but not having seen your code I can only speculate. – Julie Wang Jul 31 '19 at 14:24

0 Answers0