HTTPS and File Uploads (#139)

* Add a few fixes

* Use CopyToContainer instead of bind mounts

* Remove a local compose file

* Changes according to the comments

* Rebase with master
This commit is contained in:
Jonathan Leibiusky
2017-05-12 16:20:09 -03:00
committed by Marcos Nils
parent 61a0bb4db1
commit 8df6373327
8 changed files with 267 additions and 54 deletions

47
handlers/file_upload.go Normal file
View File

@@ -0,0 +1,47 @@
package handlers
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/play-with-docker/play-with-docker/services"
)
func FileUpload(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
instanceName := vars["instanceName"]
s := services.GetSession(sessionId)
i := services.GetInstance(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 := i.UploadFromURL(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
}
}