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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

net/http: HTTP/1.x 傳輸連接斷開:http: ContentLength=2514

net/http: HTTP/1.x 傳輸連接斷開:http: ContentLength=2514

Go
瀟瀟雨雨 2022-11-23 14:00:03
我正在嘗試將 nodejs 應(yīng)用程序轉(zhuǎn)換為 Go。在這里,我試圖將文件上傳到 B2。但我越來越 Post "https://pod-XX.backblaze.com/b2api/v2/b2_upload_file/WERTGVWGTE/cSEREf": net/http: HTTP/1.x transport connection broken: http: ContentLength=3312 with Body length 0。這是我的代碼:// open file    file, err := os.Open(location)    if err != nil {        log.Fatal(err)        return "", err    }    defer file.Close()    // create sha1 hash of file    hash := sha1.New()    if _, err := io.Copy(hash, file); err != nil {        log.Fatal(err)        return "", err    }    sha1Sum := hex.EncodeToString(hash.Sum(nil))    // http client    client := http.Client{}    req, _ := http.NewRequest("POST", b2.UploadUrl, file)    contentLength, _ := file.Stat()        req.ContentLength = contentLength.Size()  // without this, its throwing map[code:bad_request message:Missing header: Content-Length status:400]    req.Header.Set("Content-Type", "application/octet-stream")    req.Header.Set("Authorization", b2.AuthorizationToken)    req.Header.Set("X-Bz-File-Name", name)    req.Header.Set("X-Bz-Content-Sha1", sha1Sum)    res , errr := client.Do(req)    if errr != nil {        log.Fatalln(errr)        return "", errr    }僅供參考,這是完美運(yùn)行的nodejs代碼:const file = await fs.readFile(location);    const sha1 = crypto.createHash('sha1').update(file).digest("hex");    const config = {        headers: {            'Authorization': auth_token,            'X-Bz-File-Name': final_name,            'Content-Type': 'b2/x-auto',            'X-Bz-Content-Sha1': sha1        }    };    let response = await axios.post(upload_url, file, config);    return response.data['fileId'];
查看完整描述

1 回答

?
MMTTMM

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊

您在這里使用了文件:


if _, err := io.Copy(hash, file); err != nil {

        log.Fatal(err)

        return "", err

    }

使用func (*File) Seek或加載文件到內(nèi)存。



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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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