#How can I upload a file to the built in fileserver through an html form?
6 messages · Page 1 of 1 (latest)
When my file is uploaded it just goes to the root directory
I have tried this dst, err := os.Create("/static/uploads/" + handler.Filename)
but it gives an error The system cannot find the path specified.
if I change the line to this dst, err := os.Create("/static/uploads/" + handler.Filename) it works but the file is not in the static folder
I fixed it by making a new file server for uploads that is not an embedded FS:
uploadServer := http.FileServer(http.Dir("./uploads"))
router.Handler(http.MethodGet, "/uploads/*filepath", http.StripPrefix("/uploads", uploadServer))
and then
dst, err := os.Create("./uploads/" + handler.Filename)