diff --git a/pkg/storage/fs/ocis/blobstore/blobstore.go b/pkg/storage/fs/ocis/blobstore/blobstore.go index aab9f88ca48..4e362bea7d4 100644 --- a/pkg/storage/fs/ocis/blobstore/blobstore.go +++ b/pkg/storage/fs/ocis/blobstore/blobstore.go @@ -45,14 +45,14 @@ func New(root string) (*Blobstore, error) { } // Upload stores some data in the blobstore under the given key -func (bs *Blobstore) Upload(key string, data io.Reader) error { +func (bs *Blobstore) Upload(key string, file *os.File) error { f, err := os.OpenFile(bs.path(key), os.O_CREATE|os.O_WRONLY, 0700) if err != nil { return errors.Wrapf(err, "could not open blob '%s' for writing", key) } w := bufio.NewWriter(f) - _, err = w.ReadFrom(data) + _, err = w.ReadFrom(file) if err != nil { return errors.Wrapf(err, "could not write blob '%s'", key) } diff --git a/pkg/storage/fs/s3ng/blobstore/blobstore.go b/pkg/storage/fs/s3ng/blobstore/blobstore.go index 4f44268a4ed..5e19fa93ef0 100644 --- a/pkg/storage/fs/s3ng/blobstore/blobstore.go +++ b/pkg/storage/fs/s3ng/blobstore/blobstore.go @@ -22,6 +22,7 @@ import ( "context" "io" "net/url" + "os" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" @@ -59,8 +60,12 @@ func New(endpoint, region, bucket, accessKey, secretKey string) (*Blobstore, err } // Upload stores some data in the blobstore under the given key -func (bs *Blobstore) Upload(key string, reader io.Reader) error { - _, err := bs.client.PutObject(context.Background(), bs.bucket, key, reader, -1, minio.PutObjectOptions{ContentType: "application/octet-stream"}) +func (bs *Blobstore) Upload(key string, file *os.File) error { + info, err := file.Stat() + if err != nil { + return err + } + _, err = bs.client.PutObject(context.Background(), bs.bucket, key, file, info.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"}) if err != nil { return errors.Wrapf(err, "could not store object '%s' into bucket '%s'", key, bs.bucket) diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index ccce2b4fce7..5875b871a2c 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -71,7 +71,7 @@ type Tree interface { RestoreRecycleItemFunc(ctx context.Context, key, trashPath, restorePath string) (*node.Node, func() error, error) // FIXME REFERENCE use ref instead of path PurgeRecycleItemFunc(ctx context.Context, key, purgePath string) (*node.Node, func() error, error) - WriteBlob(key string, reader io.Reader) error + WriteBlob(key string, file *os.File) error ReadBlob(key string) (io.ReadCloser, error) DeleteBlob(key string) error diff --git a/pkg/storage/utils/decomposedfs/mocks/Tree.go b/pkg/storage/utils/decomposedfs/mocks/Tree.go index 8fe655b985c..93162fe68d1 100644 --- a/pkg/storage/utils/decomposedfs/mocks/Tree.go +++ b/pkg/storage/utils/decomposedfs/mocks/Tree.go @@ -277,12 +277,12 @@ func (_m *Tree) Setup(owner string) error { } // WriteBlob provides a mock function with given fields: key, reader -func (_m *Tree) WriteBlob(key string, reader io.Reader) error { - ret := _m.Called(key, reader) +func (_m *Tree) WriteBlob(key string, file *os.File) error { + ret := _m.Called(key, file) var r0 error if rf, ok := ret.Get(0).(func(string, io.Reader) error); ok { - r0 = rf(key, reader) + r0 = rf(key, file) } else { r0 = ret.Error(0) } diff --git a/pkg/storage/utils/decomposedfs/tree/tree.go b/pkg/storage/utils/decomposedfs/tree/tree.go index 934799f9e19..2b1308be316 100644 --- a/pkg/storage/utils/decomposedfs/tree/tree.go +++ b/pkg/storage/utils/decomposedfs/tree/tree.go @@ -46,7 +46,7 @@ import ( // Blobstore defines an interface for storing blobs in a blobstore type Blobstore interface { - Upload(key string, reader io.Reader) error + Upload(key string, file *os.File) error Download(key string) (io.ReadCloser, error) Delete(key string) error } @@ -678,8 +678,8 @@ func calculateTreeSize(ctx context.Context, nodePath string) (uint64, error) { } // WriteBlob writes a blob to the blobstore -func (t *Tree) WriteBlob(key string, reader io.Reader) error { - return t.blobstore.Upload(key, reader) +func (t *Tree) WriteBlob(key string, file *os.File) error { + return t.blobstore.Upload(key, file) } // ReadBlob reads a blob from the blobstore