云存储 – 可以通过 API 检索对象,但在尝试访问 MediaLink 时出现奇怪的错误。

huangapple go评论83阅读模式
英文:

Cloud Storage - can retrieve Object via API, but strange errors when trying to access the MediaLink

问题

我正在使用golang在appengine上(go版本go1.2.1(appengine-1.9.3)linux/386)。

我的新应用在尝试读取云存储文件内容时遇到了问题。我可以通过google-api-go-client获取对象信息,MediaLink给我提供了一个URL,如下所示:

https://www.googleapis.com/storage/v1beta2/b/bucket/o/profile%2Fpath_to_the_file.jpeg?generation=1402107955298000&alt=media

在dev_app_server或appengine上,当我尝试urlfetch这个jpeg时,我得到了"404 Not Found"的错误。当我将相同的URL粘贴到浏览器中时,我得到一个307重定向,然后是一个新的URL返回200,它看起来像这样:

https://storage.googleapis.com/bucket/profile%2Fpath_to_the_file.jpeg?generation=1402107955298000

我进行了一个测试,先是对www.googleapis.com的URL进行了urlfetch请求,然后是对storage.googleapis.com的URL进行了请求。第一个URL返回404,但第二个URL返回200 OK。我在另一个应用中几乎有相同的代码工作正常-为什么在这种情况下会得到错误的404?

谢谢,
Tim.

英文:

I am using golang on appengine (go version go1.2.1 (appengine-1.9.3) linux/386)

My new app is having trouble when trying to read a cloud storage file's contents. I can get the Object info via google-api-go-client, and the MediaLink gives me a URL like this:

https://www.googleapis.com/storage/v1beta2/b/bucket/o/profile%2Fpath_to_the_file.jpeg?generation=1402107955298000&alt=media

On dev_app_server or appengine, when I try to urlfetch this jpeg, I get "404 Not Found". When I paste the same URL into my browser, I get a 307 redirect, and then a 200 for a new URL that looks likes this:

https://storage.googleapis.com/bucket/profile%2Fpath_to_the_file.jpeg?generation=1402107955298000

I tried a test and just did a urlfetch request for first a www.googleapis.com URL, and then a storage.googleapis.com URL. The first URL gives a 404, but the second URL gives 200 OK. I have nearly identical code working in another app - why am I getting the false 404s in this instance?

Thanks,
Tim.

答案1

得分: 1

显然,这是一个与golang如何解析URL字符串并将其转换为net/url结构有关的问题。您可以使用URL.Opaque字段来解决这个问题。我没有编写这段代码,但是这里有一个示例,展示了googleapi如何解决相同的问题以保留路径中的%2F分隔符。

http://play.golang.org/p/TkKRROJTfb

英文:

Apparently this is an issue with how golang parses a URL string and translates it to a net/url struct. You can use the URL.Opaque field to work around this behavior. I didn't write this code, but here is an example of how googleapi addresses this same issue in order to preserve the %2F separators in the path.

http://play.golang.org/p/TkKRROJTfb

huangapple
  • 本文由 发表于 2014年6月7日 11:54:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/24093482.html
  • go
  • google-api-go-client
  • google-app-engine
  • google-cloud-storage
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定