Giter VIP home page Giter VIP logo

Comments (7)

kurin avatar kurin commented on August 20, 2024

I don't think this is me:

2018/09/12 10:53:43 >> b2_upload_file uri: https://pod-000-1039-13.backblaze.com/b2api/v1/b2_upload_file/72bdd680e4a7c5e76353081d/c001_v0001039_t0054 {X-Bz-Content-Sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709;X-Blazer-Request-Id: 14;X-Bz-Test-Mode: fail_some_uploads,expire_some_account_authorization_tokens;X-Bz-File-Name: empty;Content-Type: application/octet-stream;Content-Length: 0;User-Agent: integration-test b2-test blazer/0.5.1} (no args)
2018/09/12 10:53:43 << b2_upload_file (14) 400  {Cache-Control: max-age=0, no-cache, no-store; Content-Type: application/json;charset=utf-8; Content-Length: 91; Date: Wed, 12 Sep 2018 17:53:43 GMT} ({
  "code": "bad_request",
  "message": "Missing header: Content-Length",
  "status": 400
})
2018/09/12 10:53:43 error writing empty: b2_upload_file: 400: Missing header: Content-Length

from blazer.

kurin avatar kurin commented on August 20, 2024

Although I think if you create a writer and immediately Close it, you should get an empty object as well, and right now you don't, with no error.

from blazer.

kurin avatar kurin commented on August 20, 2024

I couldn't open a bug on the backblaze site because the recaptcha form was broken, but I'll try again later.

from blazer.

AndreKR avatar AndreKR commented on August 20, 2024

It's not just B2 either, this works for uploading an empty file:

// Login
req, _ := http.NewRequest("GET", "https://api.backblazeb2.com/b2api/v1/b2_authorize_account", nil)
req.SetBasicAuth(username, password)
resp, err := http.DefaultClient.Do(req)
fmt.Println(err)
d := json.NewDecoder(resp.Body)
var auth struct {
	ApiUrl             string
	AuthorizationToken string
}
err = d.Decode(&auth)
resp.Body.Close()
fmt.Println(err)
fmt.Println(auth)

// Get upload URL
req, _ = http.NewRequest("POST", auth.ApiUrl+"/b2api/v1/b2_get_upload_url", bytes.NewReader([]byte(`{"bucketId": "`+bucket+`"}`)))
req.Header.Set("Authorization", auth.AuthorizationToken)
resp, err = http.DefaultClient.Do(req)
fmt.Println(err)
d = json.NewDecoder(resp.Body)
var upload struct {
	AuthorizationToken string
	UploadUrl          string
}
err = d.Decode(&upload)
resp.Body.Close()
fmt.Println(err)
fmt.Println(upload)

// Upload
req, _ = http.NewRequest("POST", upload.UploadUrl, bytes.NewReader([]byte(""))) // empty body
req.Header.Set("Authorization", upload.AuthorizationToken)
req.Header.Set("X-Bz-File-Name", "empty")
req.Header.Set("Content-Type", "application/octet-stream")
req.Header.Set("Content-Length", "0") // it works without this, probably Go sets it
req.Header.Set("X-Bz-Content-Sha1", "da39a3ee5e6b4b0d3255bfef95601890afd80709")
resp, err = http.DefaultClient.Do(req)
fmt.Println(err)
b, err := ioutil.ReadAll(resp.Body)
fmt.Println(err)
fmt.Println(string(b))

from blazer.

kurin avatar kurin commented on August 20, 2024

It looks like the http lib is setting the transfer encoding to "chunked" and then sending a non-empty body for reasons I don't yet understand.

from blazer.

kurin avatar kurin commented on August 20, 2024
POST /b2api/v1/b2_upload_file/22ed46e0b407c5f76353081d/c001_v0001105_t0039 HTTP/1.1
Host: pod-000-1105-00.backblaze.com
User-Agent: integration-test b2-test blazer/0.5.1
Transfer-Encoding: chunked
Authorization: boop
Content-Type: application/octet-stream
X-Blazer-Method: b2_upload_file
X-Blazer-Request-Id: 7
X-Bz-Content-Sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
X-Bz-File-Name: empty
X-Bz-Test-Mode: fail_some_uploads
X-Bz-Test-Mode: expire_some_account_authorization_tokens
Accept-Encoding: gzip

0


I think I want to explicitly set the encoding to "identity" but uh, that's not working.

from blazer.

kurin avatar kurin commented on August 20, 2024
// outgoingLength reports the Content-Length of this outgoing (Client) request.
// It maps 0 into -1 (unknown) when the Body is non-nil.
func (r *Request) outgoingLength() int64 {

Cool. Coolcoolcool.

from blazer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.