Skip to content

Commit a950a8b

Browse files
author
cong.li
committed
update
1 parent 4d14dfd commit a950a8b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,20 @@ func (f *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
736736
upath = "/" + upath
737737
r.URL.Path = upath
738738
}
739-
if r.Method == http.MethodPost || r.Method == http.MethodPut {
739+
if r.Method == http.MethodPost {
740740
if err := uploadFile(w, r, f.root, path.Clean(upath)); err != nil {
741741
log.Printf("upload file failed %s\n", err)
742742
w.WriteHeader(http.StatusInternalServerError)
743743
}
744744
return
745745
}
746+
if r.Method == http.MethodPut {
747+
if err := uploadFile(w, r, f.root, path.Dir(upath)); err != nil {
748+
log.Printf("upload file failed %s\n", err)
749+
w.WriteHeader(http.StatusInternalServerError)
750+
}
751+
return
752+
}
746753
serveFile(w, r, f.root, path.Clean(upath), true)
747754
log.Printf("%s %s\n", r.Method, filepath.Join(dir, upath))
748755
}
@@ -755,6 +762,7 @@ func uploadFile(w http.ResponseWriter, r *http.Request, fs FileSystem, name stri
755762
log.Printf("read upload form failed %s\n", err)
756763
return err
757764
}
765+
758766
defer file.Close()
759767
log.Printf("upload file filename=%s to directory %s", filename, path.Join(dir, name))
760768
if _, err := os.Stat(path.Join(dir, name)); err != nil {

0 commit comments

Comments
 (0)