Comments (7)
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.
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.
I couldn't open a bug on the backblaze site because the recaptcha form was broken, but I'll try again later.
from blazer.
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.
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.
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.
// 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)
- Add an option to turn off error handling
- EOF issue with zfsbackup-go HOT 24
- There is a race condition when a writer is cancelled. HOT 1
- No docs on creating Bucket object
- Slightly extend `base` interface for stateless programs HOT 4
- How to set custom info headers
- Get a file at a specific version (ID) HOT 3
- How to perform Delete operation on sequence of .JPEG files? HOT 2
- Error while trying to create *b2.Bucket object - bucket not found HOT 3
- Generating Auth Token and re-using it for list of image files stored on B2 bucket
- Question about the state of this library. HOT 1
- Operations on 0-byte-files fail with 416: out of content HOT 6
- Is bonfire able to be used as a local emulator? HOT 3
- Possible crashing bug HOT 2
- Infinite loop in NewClient() if system certificates are not installed HOT 1
- Supply optional bucketName parameter to listBuckets HOT 1
- Deleting a file downloads it first HOT 2
- go-fuzz is deprecated with Go 1.18
- Upload file with custom content type? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blazer.