Skip to content

Commit

Permalink
Provide fileSize when upload to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasSko committed Jul 28, 2021
1 parent 1231312 commit be1e7de
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/storage/fs/ocis/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/storage/fs/s3ng/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"io"
"net/url"
"os"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/mocks/Tree.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be1e7de

Please sign in to comment.