-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass contentLength to the worker #791
Conversation
Hi @mike76-dev, thanks for your contribution, could you give a little more context to the PR, I don't really follow how or why it is useful and where we are using the |
I'm encrypting the data in |
worker/client/client.go
Outdated
@@ -194,6 +194,7 @@ func (c *Client) UploadMultipartUploadPart(ctx context.Context, r io.Reader, buc | |||
panic(err) | |||
} | |||
req.SetBasicAuth("", c.c.WithContext(ctx).Password) | |||
req.Header.Add("X-Content-Length", fmt.Sprintf("%d", contentLength)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try setting req.ContentLength = contentLength
instead. That way the Content-Length
header will be set.
But contentLength
should be part of opts
and only be set if opts.ContentLength != 0
.
It would also help us a lot if you did the same for PutObject
in backend.go
since that also seems to have a size
that is currently not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to go the extra mile you can extend the client methods to try and cast r.(io.Seeker)
iff opts.ContentLength = 0
and then seek to the end and back to the beginning to determine the content length of the input. That would make sure that calling the client methods with an os.File
or bytes.Reader
will set the content length implicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make sure that calling the client methods with an
os.File
orbytes.Reader
will set the content length implicitly.
So, no need to set req.ContentLength = <offset>
in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in that case we don't set it and just use the seeker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sry I misunderstood your question. We still need to set the content length. Just not from the input but from the offset of the seeker.
Please also make sure to handle all errors
api/object.go
Outdated
@@ -196,11 +196,13 @@ type ( | |||
ContractSet string | |||
MimeType string | |||
DisablePreshardingEncryption bool | |||
Size int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Size int64 | |
ContentLength int64 |
Thanks for the contribution! |
There is an unused
contentLength
field ins3.UploadPart
. On the other hand, when a file is uploaded from therenterd
UI, theContent-Length
header is always set.Unfortunately, when I try to set the
Content-Length
header in the API request to the worker, it gets stripped out (probably because of the encoding). For this reason, I setX-Content-Length
, which can also be checked by the handler.