Skip to content

Commit 912f27a

Browse files
authored
fix: add directory creation code to partial upload handler (#2575) (#2580)
1 parent 4e28cc1 commit 912f27a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

files/file.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
)
2525

2626
const PERM = 0664
27+
const DIR_PERM = 0755
2728

2829
// FileInfo describes a file.
2930
type FileInfo struct {

http/tus_handlers.go

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"net/http"
88
"os"
9+
"path/filepath"
910
"strconv"
1011

1112
"github.com/spf13/afero"
@@ -28,6 +29,13 @@ func tusPostHandler() handleFunc {
2829
if !d.user.Perm.Create || !d.Check(r.URL.Path) {
2930
return http.StatusForbidden, nil
3031
}
32+
33+
dirPath := filepath.Dir(r.URL.Path)
34+
if _, statErr := d.user.Fs.Stat(dirPath); os.IsNotExist(statErr) {
35+
if mkdirErr := d.user.Fs.MkdirAll(dirPath, files.DIR_PERM); mkdirErr != nil {
36+
return http.StatusInternalServerError, err
37+
}
38+
}
3139
case err != nil:
3240
return errToStatus(err), err
3341
}

0 commit comments

Comments
 (0)