feat: add stream upload support and related configurations

This commit is contained in:
krau
2025-02-28 11:09:24 +08:00
parent 9c7ed833fd
commit 8e2dd37155
6 changed files with 207 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package local
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
@@ -55,3 +56,18 @@ func (l *Local) Save(ctx context.Context, filePath, storagePath string) error {
func (l *Local) JoinStoragePath(task types.Task) string {
return filepath.Join(l.config.BasePath, task.StoragePath)
}
func (l *Local) NewUploadStream(ctx context.Context, path string) (io.WriteCloser, error) {
absPath, err := filepath.Abs(path)
if err != nil {
return nil, err
}
if err := fileutil.CreateDir(filepath.Dir(absPath)); err != nil {
return nil, err
}
file, err := os.Create(absPath)
if err != nil {
return nil, err
}
return file, nil
}