第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

將文件從 url 發(fā)送到 cloudflare 圖像失敗

將文件從 url 發(fā)送到 cloudflare 圖像失敗

Go
慕斯709654 2022-11-28 10:28:11
我正在使用 Google App 引擎,這意味著只允許通過云存儲寫入文件。當(dāng) API 被點(diǎn)擊時,我可以毫無問題地獲取文件并將其存儲在谷歌云存儲中。該函數(shù)只返回保存它的 URL。我想獲取該圖像 URL,然后將其發(fā)送到 Cloudflare 圖像,因?yàn)樗鼈冊试S您創(chuàng)建變體。type ImageResult struct {            Result struct {                ID                string    `json:"id"`                Filename          string    `json:"filename"`                Uploaded          time.Time `json:"uploaded"`                RequireSignedURLs bool      `json:"requireSignedURLs"`                Variants          []string  `json:"variants"`            } `json:"result"`            ResultInfo interface{}   `json:"result_info"`            Success    bool          `json:"success"`            Errors     []interface{} `json:"errors"`            Messages   []interface{} `json:"messages"`}以上是表示 Cloudflare 響應(yīng)的結(jié)構(gòu)。下面是直接獲取谷歌云存儲 URL 并在將其發(fā)送到 Cloudflare 之前“下載”它的函數(shù)。func CloudFlareURL(url, filename string) (*ImageResult, error) {    cloudFlareUrl := "https://api.cloudflare.com/client/v4/accounts/" + konsts.CloudFlareAcc + "/images/v1"    cloudFlareAuth := "Bearer " + konsts.CloudFlareApi    r, err := http.Get(url)    if err != nil {        return nil, errors.Wrap(err, "Couldn't get the file")    }    if r.StatusCode != 200 {        return nil, errors.New("Couldn't get the file")    }    defer r.Body.Close()    buff := make([]byte, 4096)    _, err = r.Body.Read(buff)    req, err := http.NewRequest("POST", cloudFlareUrl, bytes.NewReader(buff))    if err != nil {        return nil, errors.Wrap(err, "Couldn't create the request")    }    req.Header.Set("Content-Type", "multipart/form-data")    req.Header.Set("Authorization", cloudFlareAuth)    client := &http.Client{}    resp, err := client.Do(req)    if err != nil {        return nil, errors.Wrap(err, "Couldn't send the request")    }這是錯誤信息; 尋找值開頭的無效字符“E”無法解組響應(yīng)正文現(xiàn)在在我的筆記本電腦上,如果我在發(fā)送文件后運(yùn)行 api 服務(wù)器,我可以將它保存在磁盤上,打開它并毫無問題地發(fā)送到 cloudflare。
查看完整描述

1 回答

?
慕森王

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個贊

好的,對于遇到此問題的其他人。我解決了。


r, err := http.Get(url)

    if err != nil {

        return nil, errors.Wrap(err, "Couldn't get the file")

    }

    if r.StatusCode != 200 {

        return nil, errors.New("Couldn't get the file")

    }

    defer r.Body.Close()

    b := &bytes.Buffer{}

    a := make([]byte, 4096)

    wr := multipart.NewWriter(b)

    part, err := wr.CreateFormFile("file", filename)

    if err != nil {

        return nil, errors.Wrap(err, "Couldn't create the form file")

    }

    _, err = io.CopyBuffer(part, r.Body, a)

    wr.Close()


    req, err := http.NewRequest("POST", cloudFlareUrl, bytes.NewReader(b.Bytes()))

    if err != nil {

        return nil, errors.Wrap(err, "Couldn't create the request")

    }

    // req.Header.Set("Content-Type", "multipart/form-data")

    req.Header.Set("Content-Type", wr.FormDataContentType())

    req.Header.Set("Authorization", cloudFlareAuth)


查看完整回答
反對 回復(fù) 2022-11-28
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號