diff --git a/providers/azure/azure.go b/providers/azure/azure.go index a5f41ed1..66c0e26d 100644 --- a/providers/azure/azure.go +++ b/providers/azure/azure.go @@ -295,17 +295,23 @@ func (b *Bucket) Exists(ctx context.Context, name string) (bool, error) { } // Upload the contents of the reader as an object into the bucket. -func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error { +func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) (int64, error) { level.Debug(b.logger).Log("msg", "uploading blob", "blob", name) + size, err := objstore.TryToGetSize(r) + if err != nil { + return 0, errors.Wrapf(err, "failed to get size apriori to upload %s", name) + } + blobClient := b.containerClient.NewBlockBlobClient(name) opts := &blockblob.UploadStreamOptions{ BlockSize: 3 * 1024 * 1024, Concurrency: 4, } + if _, err := blobClient.UploadStream(ctx, r, opts); err != nil { - return errors.Wrapf(err, "cannot upload Azure blob, address: %s", name) + return 0, errors.Wrapf(err, "cannot upload Azure blob, address: %s", name) } - return nil + return size, nil } // Delete removes the object with the given name. diff --git a/providers/s3/s3.go b/providers/s3/s3.go index 5498bb22..ced23439 100644 --- a/providers/s3/s3.go +++ b/providers/s3/s3.go @@ -495,7 +495,7 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) (int64, e if size < int64(partSize) { partSize = 0 } - if _, err := b.client.PutObject( + resp, err := b.client.PutObject( ctx, b.name, name, @@ -511,11 +511,12 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) (int64, e // TODO(bwplotka): Consider adjusting this number to GOMAXPROCS or to expose this in config if it becomes bottleneck. NumThreads: 4, }, - ); err != nil { + ) + if err != nil { return 0, errors.Wrap(err, "upload s3 object") } - return size, nil + return resp.Size, nil } // Attributes returns information about the specified object.