From 01cb256b84db3eb170d13d1688c077af347241a6 Mon Sep 17 00:00:00 2001 From: Tim Gallant Date: Sat, 21 Mar 2020 14:49:12 -0700 Subject: [PATCH] box: pass options to rest.Opts for uploadPart --- backend/box/box.go | 2 +- backend/box/upload.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/box/box.go b/backend/box/box.go index 60b3160de..e444b9015 100644 --- a/backend/box/box.go +++ b/backend/box/box.go @@ -1254,7 +1254,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op if size <= int64(o.fs.opt.UploadCutoff) { err = o.upload(ctx, in, leaf, directoryID, modTime, options...) } else { - err = o.uploadMultipart(ctx, in, leaf, directoryID, size, modTime) + err = o.uploadMultipart(ctx, in, leaf, directoryID, size, modTime, options...) } return err } diff --git a/backend/box/upload.go b/backend/box/upload.go index b832bf1c3..e259740c2 100644 --- a/backend/box/upload.go +++ b/backend/box/upload.go @@ -54,7 +54,7 @@ func sha1Digest(digest []byte) string { } // uploadPart uploads a part in an upload session -func (o *Object) uploadPart(ctx context.Context, SessionID string, offset, totalSize int64, chunk []byte, wrap accounting.WrapFn) (response *api.UploadPartResponse, err error) { +func (o *Object) uploadPart(ctx context.Context, SessionID string, offset, totalSize int64, chunk []byte, wrap accounting.WrapFn, options ...fs.OpenOption) (response *api.UploadPartResponse, err error) { chunkSize := int64(len(chunk)) sha1sum := sha1.Sum(chunk) opts := rest.Opts{ @@ -64,6 +64,7 @@ func (o *Object) uploadPart(ctx context.Context, SessionID string, offset, total ContentType: "application/octet-stream", ContentLength: &chunkSize, ContentRange: fmt.Sprintf("bytes %d-%d/%d", offset, offset+chunkSize-1, totalSize), + Options: options, ExtraHeaders: map[string]string{ "Digest": sha1Digest(sha1sum[:]), }, @@ -171,7 +172,7 @@ func (o *Object) abortUpload(ctx context.Context, SessionID string) (err error) } // uploadMultipart uploads a file using multipart upload -func (o *Object) uploadMultipart(ctx context.Context, in io.Reader, leaf, directoryID string, size int64, modTime time.Time) (err error) { +func (o *Object) uploadMultipart(ctx context.Context, in io.Reader, leaf, directoryID string, size int64, modTime time.Time, options ...fs.OpenOption) (err error) { // Create upload session session, err := o.createUploadSession(ctx, leaf, directoryID, size) if err != nil { @@ -236,7 +237,7 @@ outer: defer wg.Done() defer o.fs.uploadToken.Put() fs.Debugf(o, "Uploading part %d/%d offset %v/%v part size %v", part+1, session.TotalParts, fs.SizeSuffix(position), fs.SizeSuffix(size), fs.SizeSuffix(chunkSize)) - partResponse, err := o.uploadPart(ctx, session.ID, position, size, buf, wrap) + partResponse, err := o.uploadPart(ctx, session.ID, position, size, buf, wrap, options...) if err != nil { err = errors.Wrap(err, "multipart upload failed to upload part") select {