add Upload and Download files

This commit is contained in:
2026-07-12 18:05:52 +07:00
parent 2ecc6ecd6a
commit 487b1aa436
13 changed files with 854 additions and 63 deletions
+14 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"mime"
"path/filepath"
"time"
"github.com/kzzan/s3kit"
)
@@ -28,6 +29,17 @@ func NewRustFSStorage(
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
err = client.CreateBucket(
ctx,
bucket,
)
if err != nil {
return nil, err
}
return &storage{
client: client,
bucket: bucket,
@@ -35,7 +47,8 @@ func NewRustFSStorage(
}
func (s *storage) Put(ctx context.Context, file *File) error {
return s.client.PutObjectBytes(ctx, s.bucket, file.Name, file.Data, file.Mime)
mime := s.getMimeType(file.Name)
return s.client.PutObjectBytes(ctx, s.bucket, file.Name, file.Data, mime)
}
func (s *storage) Get(ctx context.Context, filename string) (*File, error) {