From 912f27a9e3286ee4bf2a27b366a1d35b3b55799c Mon Sep 17 00:00:00 2001 From: M A E R Y O Date: Mon, 31 Jul 2023 19:38:11 +0900 Subject: [PATCH] fix: add directory creation code to partial upload handler (#2575) (#2580) --- files/file.go | 1 + http/tus_handlers.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/files/file.go b/files/file.go index a077b062..5372246c 100644 --- a/files/file.go +++ b/files/file.go @@ -24,6 +24,7 @@ import ( ) const PERM = 0664 +const DIR_PERM = 0755 // FileInfo describes a file. type FileInfo struct { diff --git a/http/tus_handlers.go b/http/tus_handlers.go index 8df38d4b..04ea1202 100644 --- a/http/tus_handlers.go +++ b/http/tus_handlers.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "os" + "path/filepath" "strconv" "github.com/spf13/afero" @@ -28,6 +29,13 @@ func tusPostHandler() handleFunc { if !d.user.Perm.Create || !d.Check(r.URL.Path) { return http.StatusForbidden, nil } + + dirPath := filepath.Dir(r.URL.Path) + if _, statErr := d.user.Fs.Stat(dirPath); os.IsNotExist(statErr) { + if mkdirErr := d.user.Fs.MkdirAll(dirPath, files.DIR_PERM); mkdirErr != nil { + return http.StatusInternalServerError, err + } + } case err != nil: return errToStatus(err), err }