@@ -736,13 +736,20 @@ func (f *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
736
736
upath = "/" + upath
737
737
r .URL .Path = upath
738
738
}
739
- if r .Method == http .MethodPost || r . Method == http . MethodPut {
739
+ if r .Method == http .MethodPost {
740
740
if err := uploadFile (w , r , f .root , path .Clean (upath )); err != nil {
741
741
log .Printf ("upload file failed %s\n " , err )
742
742
w .WriteHeader (http .StatusInternalServerError )
743
743
}
744
744
return
745
745
}
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
+ }
746
753
serveFile (w , r , f .root , path .Clean (upath ), true )
747
754
log .Printf ("%s %s\n " , r .Method , filepath .Join (dir , upath ))
748
755
}
@@ -755,6 +762,7 @@ func uploadFile(w http.ResponseWriter, r *http.Request, fs FileSystem, name stri
755
762
log .Printf ("read upload form failed %s\n " , err )
756
763
return err
757
764
}
765
+
758
766
defer file .Close ()
759
767
log .Printf ("upload file filename=%s to directory %s" , filename , path .Join (dir , name ))
760
768
if _ , err := os .Stat (path .Join (dir , name )); err != nil {
0 commit comments