亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 GO 中將 Json Array 從 GAE 上傳到 Cloud Storage

在 GO 中將 Json Array 從 GAE 上傳到 Cloud Storage

Go
慕的地6264312 2021-10-04 16:36:57
我嘗試將應用引擎應用程序使用以下代碼發布的 json 數組上傳到谷歌云存儲:saveData : function saveData() {  var _this = this,      save = this.shadowRoot.querySelector('#save-data'),      subData = JSON.stringify(_this.app.userSession);  save.url="url";  save.body = subData;  save.go();}發布的消息與下面發布的代碼一起處理。使用此代碼,我可以在以用戶 ID 命名的云存儲桶上創建一個文件夾。我想做的是將整個 json 數組復制到文件夾中 - 即下面代碼中的變量 f。我嘗試使用 io.Copy(wc, f) 但它給了我以下錯誤:不能在 io.Copy 的參數中使用內容(類型 userData)作為類型 io.Reader:userData 沒有實現 io.Reader(缺少 Read 方法)顯然我做錯了什么,但我很新,我完全被卡住了。有人能幫我嗎?package exptimport (    "bytes"    "encoding/json"    "io/ioutil"    "log"    "net/http"    "golang.org/x/net/context"    "golang.org/x/oauth2"    "golang.org/x/oauth2/google"    "google.golang.org/appengine"    "google.golang.org/appengine/file"    "google.golang.org/appengine/urlfetch"    "google.golang.org/cloud"    "google.golang.org/cloud/storage")var bucket = "expt"func init() {    http.HandleFunc("/", handleStatic)    http.HandleFunc("/save", saveJson)}func handleStatic(w http.ResponseWriter, r *http.Request) {    w.Header().Set("Cache-Control", "no-cache")    http.ServeFile(w, r, "static/"+r.URL.Path)}type Result map[string]interface {}type userData struct {    id     string    age    string    gender string}func testA(r *http.Request) userData {    defer r.Body.Close()    body, err := ioutil.ReadAll(r.Body)    var userDataCurr userData    if err != nil {        log.Printf("Couldn't read request body: %s", err)    } else {        var f Result        err := json.Unmarshal(body, &f)        if err != nil {            log.Println("Error: %s", err)        } else {            user := f["user"].(map[string]interface{})            userDataCurr.id = user["id"].(string)        }    }    return userDataCurr}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號