fix: add directory creation code to partial upload handler (#2575) (#2580)

This commit is contained in:
M A E R Y O 2023-07-31 19:38:11 +09:00 committed by GitHub
parent 4e28cc13c9
commit 912f27a9e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import (
)
const PERM = 0664
const DIR_PERM = 0755
// FileInfo describes a file.
type FileInfo struct {

View File

@ -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
}