1
0
Fork 0
mirror of https://github.com/Luzifer/share.git synced 2024-12-20 10:31:16 +00:00
share/http.go
Knut Ahlers f679cd3785
Force bootstrap to apply gzip encoding
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-05-13 00:05:06 +02:00

32 lines
822 B
Go

package main
import (
"net/http"
log "github.com/sirupsen/logrus"
)
func doListen() error {
http.HandleFunc("/post", simpleFilePost)
return http.ListenAndServe(cfg.Listen, nil)
}
func simpleFilePost(res http.ResponseWriter, r *http.Request) {
f, fh, err := r.FormFile("file")
if err != nil {
log.WithError(err).Error("Unable to retrieve file from request")
http.Error(res, "Could not retrieve your file", http.StatusBadRequest)
return
}
url, err := executeUpload(fh.Filename, f, true, "", false)
if err != nil {
log.WithError(err).Error("Uploading file from HTTP request failed")
http.Error(res, "Failed to upload file. For details see the log.", http.StatusInternalServerError)
return
}
res.Header().Set("Content-Type", "text/plain")
res.WriteHeader(http.StatusOK)
res.Write([]byte(url))
}