Skip to content

Commit

Permalink
Merge pull request #791 from mike76-dev/master
Browse files Browse the repository at this point in the history
Pass contentLength to the worker
  • Loading branch information
ChrisSchinnerl authored Dec 6, 2023
2 parents e876aa5 + 6da810d commit 23cb783
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ type (
ContractSet string
MimeType string
DisablePreshardingEncryption bool
ContentLength int64
}

UploadMultipartUploadPartOptions struct {
DisablePreshardingEncryption bool
EncryptionOffset int
ContentLength int64
}
)

Expand Down
5 changes: 4 additions & 1 deletion s3/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ func (s *s3) DeleteObject(ctx context.Context, bucketName, objectName string) (g
// TODO: Metadata is currently ignored. The backend requires an update to
// support it.
func (s *s3) PutObject(ctx context.Context, bucketName, key string, meta map[string]string, input io.Reader, size int64) (gofakes3.PutObjectResult, error) {
opts := api.UploadObjectOptions{}
opts := api.UploadObjectOptions{
ContentLength: size,
}
if ct, ok := meta["Content-Type"]; ok {
opts.MimeType = ct
}
Expand Down Expand Up @@ -403,6 +405,7 @@ func (s *s3) CreateMultipartUpload(ctx context.Context, bucket, key string, meta
func (s *s3) UploadPart(ctx context.Context, bucket, object string, id gofakes3.UploadID, partNumber int, contentLength int64, input io.Reader) (*gofakes3.UploadPartResult, error) {
res, err := s.w.UploadMultipartUploadPart(ctx, input, bucket, object, string(id), partNumber, api.UploadMultipartUploadPartOptions{
DisablePreshardingEncryption: true,
ContentLength: contentLength,
})
if err != nil {
return nil, gofakes3.ErrorMessage(gofakes3.ErrInternal, err.Error())
Expand Down
30 changes: 30 additions & 0 deletions worker/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ func (c *Client) UploadMultipartUploadPart(ctx context.Context, r io.Reader, buc
panic(err)
}
req.SetBasicAuth("", c.c.WithContext(ctx).Password)
if opts.ContentLength != 0 {
req.ContentLength = opts.ContentLength
} else {
if s, ok := r.(io.Seeker); ok {
length, err := s.Seek(0, io.SeekEnd)
if err != nil {
return nil, err
}
_, err = s.Seek(0, io.SeekStart)
if err != nil {
return nil, err
}
req.ContentLength = length
}
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -225,6 +240,21 @@ func (c *Client) UploadObject(ctx context.Context, r io.Reader, bucket, path str
panic(err)
}
req.SetBasicAuth("", c.c.WithContext(ctx).Password)
if opts.ContentLength != 0 {
req.ContentLength = opts.ContentLength
} else {
if s, ok := r.(io.Seeker); ok {
length, err := s.Seek(0, io.SeekEnd)
if err != nil {
return nil, err
}
_, err = s.Seek(0, io.SeekStart)
if err != nil {
return nil, err
}
req.ContentLength = length
}
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
Expand Down

0 comments on commit 23cb783

Please sign in to comment.