Merge branch 'next' into mongo_storage

This commit is contained in:
Marcos Lilljedahl
2017-07-18 14:40:22 -03:00
19 changed files with 5114 additions and 5093 deletions

View File

@@ -4,6 +4,7 @@ import (
"io"
"log"
"net/http"
"path/filepath"
"github.com/gorilla/mux"
)
@@ -20,7 +21,10 @@ func FileUpload(rw http.ResponseWriter, req *http.Request) {
// has a url query parameter, ignore body
if url := req.URL.Query().Get("url"); url != "" {
err := core.InstanceUploadFromUrl(i, req.URL.Query().Get("url"))
_, fileName := filepath.Split(url)
err := core.InstanceUploadFromUrl(i, fileName, "", req.URL.Query().Get("url"))
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
@@ -35,6 +39,8 @@ func FileUpload(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusBadRequest)
return
}
path := req.URL.Query().Get("path")
for {
p, err := red.NextPart()
if err == io.EOF {
@@ -48,12 +54,13 @@ func FileUpload(rw http.ResponseWriter, req *http.Request) {
if p.FileName() == "" {
continue
}
err = core.InstanceUploadFromReader(i, p.FileName(), p)
err = core.InstanceUploadFromReader(i, p.FileName(), path, p)
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
return
}
log.Printf("Uploaded [%s] to [%s]\n", p.FileName(), i.Name)
}
rw.WriteHeader(http.StatusOK)