Files
play-with-docker/handlers/file_upload.go
Jonathan Leibiusky @xetorthio 3d96760a98 WIP
2017-05-23 19:29:36 -03:00

47 lines
950 B
Go

package handlers
import (
"log"
"net/http"
"github.com/gorilla/mux"
)
func FileUpload(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
instanceName := vars["instanceName"]
s := core.SessionGet(sessionId)
i := core.InstanceGet(s, instanceName)
// allow up to 32 MB which is the default
// has a url query parameter, ignore body
if url := req.URL.Query().Get("url"); url != "" {
err := core.InstanceUploadFromUrl(i, req.URL.Query().Get("url"))
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.WriteHeader(http.StatusOK)
return
} else {
// This is for multipart upload
log.Println("Not implemented yet")
/*
err := req.ParseMultipartForm(32 << 20)
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusBadRequest)
return
}
*/
rw.WriteHeader(http.StatusInternalServerError)
return
}
}