mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: file upload handler
This commit is contained in:
@@ -11,7 +11,7 @@ type FileData struct {
|
||||
}
|
||||
|
||||
func (file FileData) Read(p []byte) (n int, err error) {
|
||||
return file.Read(p)
|
||||
return file.File.Read(p)
|
||||
}
|
||||
|
||||
func (file FileData) GetMIMEType() string {
|
||||
@@ -23,7 +23,7 @@ func (file FileData) GetSize() uint64 {
|
||||
}
|
||||
|
||||
func (file FileData) Close() error {
|
||||
return file.Close()
|
||||
return file.File.Close()
|
||||
}
|
||||
|
||||
func (file FileData) GetFileName() string {
|
||||
|
||||
37
pkg/filesystem/local/handler.go
Normal file
37
pkg/filesystem/local/handler.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
}
|
||||
|
||||
// Put 将文件流保存到指定目录
|
||||
func (handler Handler) Put(ctx context.Context, file io.ReadCloser, dst string) error {
|
||||
defer file.Close()
|
||||
|
||||
// 如果目标目录不存在,创建
|
||||
basePath := filepath.Dir(dst)
|
||||
if !util.Exists(basePath) {
|
||||
fmt.Println("创建", basePath)
|
||||
err := os.MkdirAll(basePath, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, file)
|
||||
return err
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package local
|
||||
Reference in New Issue
Block a user