从 Google Drive 下载公共文件 - Golang [英] Download public file from Google Drive - Golang
本文介绍了从 Google Drive 下载公共文件 - Golang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Google 云端硬盘上存储了一个 zip 文件(它是公开共享的).我想知道如何在 Golang 中下载它.当前的代码只是创建了一个名为file.zip"的空白文件:
I have a zip file stored on Google Drive (it is shared publicly). I want to know how to download it in Golang. This current code just creates a blank file named "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
I found the solution. Use: https://googledrive.com/host/ID
代替:https://docs.google.com/uc?export=download&id=ID
这篇关于从 Google Drive 下载公共文件 - Golang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文