我在Google云端硬盘上存储了一个zip文件(已公开共享)。我想知道如何在Golang中下载它。当前代码仅创建一个名为“ file.zip”的空白文件:
package main import ( "fmt" "io" "net/http" "os" ) func main() { url := "https://docs.google.com/uc?export=download&id=0B2Q7X-dUtUBebElySVh1ZS1iaTQ" fileName := "file.zip" fmt.Println("Downloading file...") output, err := os.Create(fileName) defer output.Close() response, err := http.Get(url) if err != nil { fmt.Println("Error while downloading", url, "-", eerrror) return } defer response.Body.Close() n, err := io.Copy(output, response.Body) fmt.Println(n, "bytes downloaded") }
我找到了解决方案。使用:https://googledrive.com/host/ ID
而不是:https : //docs.google.com/uc?export=download& id = ID