偷偷努力,悄无声息地变强,然后惊艳所有人!哈哈,小伙伴们又来学习啦~今天我将给大家介绍《下载谷歌云文件》,这篇文章主要会讲到等等知识点,不知道大家对其都有多少了解,下面我们就一起来看一吧!当然,非常希望大家能多多评论,给出合理的建议,我们一起学习,一起进步!
各位, 为什么存储在 google 存储桶中的可公开访问的对象的下载方式很重要?
https://storage.cloud.google.com/convertedexcelfiles/test.png
使用 wget 或 curl 等工具...似乎会混淆文件。
$ wget https://storage.cloud.google.com/convertedexcelfiles/test.png ... $ ls -all -h 56k feb 2 01:32 test.png
对于值得信赖的人来说也是如此:
package main
import (
"io"
"net/http"
"os"
)
func main() {
fileurl := "https://storage.cloud.google.com/convertedexcelfiles/test.png"
if err := downloadfile("test.png", fileurl); err != nil {
panic(err)
}
}
// downloadfile will download a url to a local file. it's efficient because it will
// write as it downloads and not load the whole file into memory.
func downloadfile(filepath string, url string) error {
// get the data
resp, err := http.get(url)
if err != nil {
return err
}
defer resp.body.close()
// create the file
out, err := os.create(filepath)
if err != nil {
return err
}
defer out.close()
// write the body to file
_, err = io.copy(out, resp.body)
return err
}
似乎唯一可靠的方法是使用 gsutil 或浏览到 gcp 控制台。想法?
是否可能是因为它返回了 302?
curl -I https://storage.cloud.google.com/convertedexcelfiles/test.png ~/Downloads/transforms/tmp HTTP/2 302 content-type: application/binary location: https://accounts.google.com/ServiceLogin?service=cds&passive=1209600&continue=https://storage.cloud.google.com/convertedexcelfiles/test.png&followup=https://storage.cloud.google.com/convertedexcelfiles/test.png content-length: 0 date: Sun, 02 Feb 2020 06:33:13 GMT server: ESF x-xss-protection: 0 x-frame-options: SAMEORIGIN x-content-type-options: nosniff alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000
如果是这种情况,如何获取可靠的链接?
解决方案
正如人们善意提到的,该文件的内容是 html....经过更仔细的查看,以下内容是显而易见的:
正如您所看到的,这两个 URL 略有不同。
https://storage.cloud.google.com/convertedexcelfiles/test.png https://storage.googleapis.com/convertedexcelfiles/test.png
第二个有效...我有一种奇怪的感觉,其他不太懂技术的人会在这方面度过一段糟糕的时光。凌晨3点,这真是令人愤怒。我应该简单地捕获该文件...但谁会想到呢!谷歌的用户界面做得很棒……见鬼?
好了,本文到此结束,带大家了解了《下载谷歌云文件》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
本文内容来源于互联网,如有侵权请联系删除。
