fix: fix upload folder is wrong (#1611)
This commit is contained in:
parent
17fa7868a4
commit
54a115ae89
2 changed files with 13 additions and 1 deletions
|
@ -59,6 +59,7 @@ func (c *CasaOS) PostUploadFile(ctx echo.Context) error {
|
||||||
|
|
||||||
identifier := ctx.FormValue("identifier")
|
identifier := ctx.FormValue("identifier")
|
||||||
fileName := ctx.FormValue("filename")
|
fileName := ctx.FormValue("filename")
|
||||||
|
relativePath := ctx.FormValue("relativePath")
|
||||||
bin, err := ctx.FormFile("file")
|
bin, err := ctx.FormFile("file")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,6 +75,7 @@ func (c *CasaOS) PostUploadFile(ctx echo.Context) error {
|
||||||
totalChunks,
|
totalChunks,
|
||||||
totalSize,
|
totalSize,
|
||||||
identifier,
|
identifier,
|
||||||
|
relativePath,
|
||||||
fileName,
|
fileName,
|
||||||
bin,
|
bin,
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
@ -63,6 +64,7 @@ func (s *FileUploadService) UploadFile(
|
||||||
totalChunks int64,
|
totalChunks int64,
|
||||||
totalSize int64,
|
totalSize int64,
|
||||||
identifier string,
|
identifier string,
|
||||||
|
relativePath string,
|
||||||
fileName string,
|
fileName string,
|
||||||
bin *multipart.FileHeader,
|
bin *multipart.FileHeader,
|
||||||
) error {
|
) error {
|
||||||
|
@ -70,7 +72,15 @@ func (s *FileUploadService) UploadFile(
|
||||||
fileInfoTemp, ok := s.uploadStatus.Load(identifier)
|
fileInfoTemp, ok := s.uploadStatus.Load(identifier)
|
||||||
var fileInfo *FileInfo
|
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 {
|
if err != nil {
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue