Doh. I think I accidentally posted a reply just to Andrew...
I wrote something like: We can certainly do that, its just not quite as
simple as "client.Get(<medialink>)" due to some URL escaping nuances that I
learned about in this thread<
https://plus.google.com/+IanRose/posts/Tzw3QZqEQZk>.
We are currently using the function below which isn't a big deal to do, it
just seemed strange to me that the google-api-go-client library had
functions for just about all operations *except* (arguably) the most common
one. So I wanted to make sure I wasn't overlooking something...
func GetFileContents(client *http.Client, bucket string, filepath string)
(io.ReadCloser, error) {
urls :=
"https://www.googleapis.com/storage/v1beta2/b/{bucket}/o/{object}?alt=media"
// you have to do this little dance because (by default) net/url will
normalize URL escaping, which means
// that will undo any "/" -> "%2f" escaping that we need to do to escape
the slashes in the filepath
req, err := http.NewRequest("GET", urls, nil)
if err != nil {
return nil, fmt.Errorf("failed to create http.Request: %s", err)
}
req.URL.Path = strings.Replace(req.URL.Path, "{bucket}",
url.QueryEscape(bucket), 1)
req.URL.Path = strings.Replace(req.URL.Path, "{object}",
url.QueryEscape(filepath), 1)
req.URL.Opaque = "//" + req.URL.Host + req.URL.Path
rsp, err := client.Do(req)
if err != nil {
rsp.Body.Close()
return nil, fmt.Errorf("failed to make http request: %s", err)
}
if rsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to make http request: %d response",
rsp.StatusCode)
}
return rsp.Body, nil
}
On Monday, April 7, 2014 3:37:56 AM UTC-4, Andrew Gerrand wrote:On 7 April 2014 11:51, Ian Rose <ianr...@gmail.com <javascript:>> wrote:Using the google-api-go-client bindings for GCS (here<
http://godoc.org/code.google.com/p/google-api-go-client/storage/v1beta2>)
I see how to get a file's metadata (via ObjectsService.Get) but how do I
just download the file's actual contents? (note that "just get the file's
metadata, read the mediaLink property out of there and then fetch that
resource" isn't really a viable answer for me as the first fetch is
entirely redundant - a file's medialink is entirely determined by its
bucket and object name).
Why can't you just use the medialink? Why do you need to use the
google-api-go-client to fetch the file if you know the link already?
Andrew
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.