aquarat / google-api-go-client

Automatically exported from code.google.com/p/google-api-go-client
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Cloud Storage API: Setting storage.Object.ContentType does not actually control the ContentType #55

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the given example.
2. Use gsutil (or curl) to examine the reported Content-Type of the object
3. Cry

What is the expected output? What do you see instead?
I would expect the object to have the ContentType I specified. Instead, 
text/plain is used as the Content-Type. 

What version of the product are you using? On what operating system?
46967f157fd4008b48fe78dcbc97ab67006a5658

Please provide any additional information below.
There are a number of issues here. First is that storage.Object purports to 
have a ContentType field that seems to be completely disregarded by the Cloud 
Storage API. The second issue is that, by default, googleapi.go tries to 
DetectContentType on the io.Reader you provide ... unless you read the source 
and see that the Reader can be pimped as a ContentTyper. This is kind of a "Not 
cool, bro." kind of API. This is especially true in that I did not expect the 
API to use uploadType=multipart even when I was uploading a simple object, so I 
had no reason to consider that my stream would need to be typed apart form my 
object.

Original issue reported on code.google.com by kelleg...@gmail.com on 24 Mar 2014 at 12:30

Attachments:

GoogleCodeExporter commented 9 years ago
Hi kelleg...@gmail.com!

We have had similar problems and in talking to enterprise support we got the 
following suggestion.  Haven't quite had time to try it yet but hopefully it 
will work:

Having Go library accept media content type will require few changes and a new 
release, which might not suit your transition timelines. MediaType in Object 
struct is not writable so we will need to introduce a new field to inject this 
value to the Http request.

Here is a workaround that we think should work in the meantime. Please keep a 
check on library upgrades to make sure this doesn't break in future.

a.) Create a wrapper over io.Reader object:

type StorageMedia struct {
io.Reader
Ctype string
}

And define a method.

// Returns Media Type.
func (sm StorageMedia) ContentType() string {
return sm.Ctype
}

b.) Now to upload an object, create a reader of type StorageMedia:

reader := StorageMedia{content, "text/css"}

And pass it to call upload service:

storage.NewObjectsService(service).Insert(bucket, &storage.Object{Name: 
object}).Media(reader).Do()

Original comment by ianros...@gmail.com on 26 Aug 2014 at 3:51