gpt4 book ai didi

go - unsupportedOutputFormat go drive api sdk v3 无法下载 gdrive 上的文件内容

转载 作者:IT王子 更新时间:2023-10-29 02:23:10 25 4
gpt4 key购买 nike

文档不清楚如何正确设置输出格式。我为谷歌驱动器上的单个文件硬编码了一个路径: http://localhost:8080/0B-zdryEj60U_OXZBVklsdG13Wlk它在下面回应:运行时进程给出了错误的 HTTP 响应:

2016/05/28 06:00:26 handleOneDoc
2016/05/28 06:00:26
2016/05/28 06:00:26 &{0xc82007a500 0xc8201121c0 0x84de40 false false 0xc82016a180 {0xc82016c820 map[] false false} map[] false 0 -1 0 false false [] 0 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0] <nil>}
2016/05/28 06:00:29 Unable to get download link %vgoogleapi: got HTTP response code 400 with body: {"error":{"errors":[{"domain":"global","reason":"unsupportedOutputFormat","message":"Unsupported Output Format","locationType":"parameter","location":"alt"}],"code":400,"message":"Unsupported Output Format"}}

来源如下:

package gwebdrive

import (
"fmt"
"golang.org/x/net/context"
_ "golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"google.golang.org/api/drive/v3"
"google.golang.org/appengine"
_ "html/template"
_ "io/ioutil"
"log"
"net/http"
"net/url"

"strings"
)

const (
assetFolder = "0B-zdryEj60U_N0NtSFJuQUdaWTA"
)

var (
//tpl *template
dir *drive.FileList
conf *jwt.Config
)

func init() {
... key config content here.
http.Handle("/list", appengineHandler(handleList))
http.Handle("/0B-zdryEj60U_OXZBVklsdG13Wlk", appengineHandler(handleOneDoc))

//http.Handle("/.+", appengineHandler(handleContent))
}

// appengineHandler wraps http.Handler to pass it a new `appengine.Context` and handle errors.
type appengineHandler func(c context.Context, w http.ResponseWriter, r *http.Request) error

func (h appengineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

c := appengine.NewContext(r)
if err := h(c, w, r); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello Darian Go Serve some Assets")

}

func handleOneDoc(c context.Context, w http.ResponseWriter, r *http.Request) error {
log.Print("handleOneDoc")
u, err := url.Parse(r.RequestURI)
if err != nil {
log.Fatalf("Unable to parse Request URL %v", err)
}
log.Printf(u.RawPath)
s := strings.Split(u.RawPath, "/")
// looking for regex for Google File ID's.

// I don't actually know the point of this call but it's needed.
client := conf.Client(appengine.NewContext(r))
// use url to decide what asset to return as data.
// for now assume url contains id.
srv, err := drive.New(client)
fileid := s[len(s)-1]
log.Print(w, fileid)
if err != nil {
log.Fatalf("Unable to retrieve drive Client %v", err)
}

dwn, err := srv.Files.Get(fileid).Download()
fmt.Fprint(w, "mimeType:image/png")

if err != nil {
log.Fatal("Unable to get download link %v", err)
}

fmt.Fprint(w, dwn.Body)

return nil

}

func handleContent(c context.Context, w http.ResponseWriter, r *http.Request) error {
log.Print("handleContent")
u, err := url.Parse(r.RequestURI)
if err != nil {
log.Fatalf("Unable to parse Request URL %v", err)
}
fmt.Fprintf(w, u.RawPath)
s := strings.Split(u.RawPath, "/")
// looking for regex for Google File ID's.

// I don't actually know the point of this call but it's needed.
client := conf.Client(appengine.NewContext(r))
// use url to decide what asset to return as data.
// for now assume url contains id.
srv, err := drive.New(client)
fileid := s[len(s)-1]
if err != nil {
log.Fatalf("Unable to retrieve drive Client %v", err)
}

dwn, err := srv.Files.Get(fileid).Download()
//service.files().get(fileId).executeMediaAndDownloadTo(w)
fmt.Fprint(w, dwn)
if err != nil {
log.Fatal("Unable to get download link %v", err)
}

//fmt.Fprint(w, dwn)

return nil

}

func handleList(c context.Context, w http.ResponseWriter, r *http.Request) error {
log.Print("just handle")

// Initiate an http.Client, the following GET request will be
// authorized and authenticated on the behalf of user@example.com.
client := conf.Client(appengine.NewContext(r))

srv, err := drive.New(client)
if err != nil {
log.Fatalf("Unable to retrieve drive Client %v", err)
}

dir, err = srv.Files.List().PageSize(10).Q("'0B-zdryEj60U_MXVkajFweXBQWHM' in parents").
Fields("files(id, kind, name, size, webViewLink)").Do()
//resp, err := srv.Files.Export(dir.Files[1].Id, dir.Files[1].MimeType).Download()
//fmt.Fprint(w, resp.Body)

if err != nil {
log.Fatalf("Unable to retrieve files.", err)
}

fmt.Fprint(w, "Files:")
if len(dir.Files) > 0 {
for _, i := range dir.Files {
fmt.Fprint(w, "%s (%s)\n", i.Name, i.WebViewLink)
}
} else {
fmt.Fprint(w, "No files found.")
}
return err
}

最佳答案

this解决方案对我有用。发现的变化是直接给出文件的URL。这会导致关于 inSufficientPermission 的另一个错误。也通过 this 解决了这个问题

关于go - unsupportedOutputFormat go drive api sdk v3 无法下载 gdrive 上的文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37495815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com