2017-12-29 22:35:57 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:55:25 +00:00
|
|
|
url, err := executeUpload(fh.Filename, f, true, "")
|
2017-12-29 22:35:57 +00:00
|
|
|
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))
|
|
|
|
}
|