GoogleCloudPlatform/appengine-gcs-client

GcsService.update overwrites the mime-type

Opened this issue · 1 comments

Attempting to update a file's options without explicitly setting the MIME type overrides the MIME type with the default "application/octet-stream".

The expected behavior is for the MIME type to remain unchanged unless explicitly set.

Example-

// Existing file with "application/javascript" MIME type
final GcsFilename gcsFilename = new GcsFilename("BUCKET", "OBJECT");

final GcsService gcs = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());

// Note MIME type is not explicitly set
final GcsFileOptions gcsFileOptions = new GcsFileOptions.Builder()
   .acl("public-read")
   .build();

gcs.update(gcsFilename, gcsFileOptions);

// File is publicly accessible, but HTTP GET returns "Content-Type: application/octet-stream"

A workaround is to first retrieve the file's MIME type via GcsService.getObject, and then set it explicitly to the same value in GcsService.update. However this results in another round trip, and in theory introduces concurrency issues.

I think it is reasonable to update GcsServiceImpl.java with a call to getMetadata if the given fileOptions does not provide a mimeType.