Skip to content

Commit

Permalink
fix: fix upload folder is wrong (#1611)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Jan 17, 2024
1 parent 17fa786 commit 54a115a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions route/v2/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (c *CasaOS) PostUploadFile(ctx echo.Context) error {

identifier := ctx.FormValue("identifier")
fileName := ctx.FormValue("filename")
relativePath := ctx.FormValue("relativePath")
bin, err := ctx.FormFile("file")

if err != nil {
Expand All @@ -74,6 +75,7 @@ func (c *CasaOS) PostUploadFile(ctx echo.Context) error {
totalChunks,
totalSize,
identifier,
relativePath,
fileName,
bin,
)
Expand Down
12 changes: 11 additions & 1 deletion service/file_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"mime/multipart"
"os"
"path/filepath"
"sync"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -63,14 +64,23 @@ func (s *FileUploadService) UploadFile(
totalChunks int64,
totalSize int64,
identifier string,
relativePath string,
fileName string,
bin *multipart.FileHeader,
) error {
s.lock.Lock()
fileInfoTemp, ok := s.uploadStatus.Load(identifier)
var fileInfo *FileInfo

file, err := os.OpenFile(path+"/"+fileName+".tmp", os.O_WRONLY|os.O_CREATE, 0644)
if relativePath != fileName {
// uploaded file is folder
folderPath := filepath.Dir(path + "/" + relativePath)
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
os.MkdirAll(folderPath, os.ModePerm)
}
}

file, err := os.OpenFile(path+"/"+relativePath+".tmp", os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
s.lock.Unlock()
return err
Expand Down

0 comments on commit 54a115a

Please sign in to comment.