Add multipart upload to instances
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -28,18 +29,34 @@ func FileUpload(rw http.ResponseWriter, req *http.Request) {
|
|||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
// This is for multipart upload
|
red, err := req.MultipartReader()
|
||||||
log.Println("Not implemented yet")
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
/*
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
err := req.ParseMultipartForm(32 << 20)
|
return
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
p, err := red.NextPart()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.FileName() == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = core.InstanceUploadFromReader(i, p.FileName(), p)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
rw.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
log.Printf("Uploaded [%s] to [%s]\n", p.FileName(), i.Name)
|
||||||
rw.WriteHeader(http.StatusInternalServerError)
|
}
|
||||||
|
rw.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,18 @@ func (p *pwd) InstanceUploadFromUrl(instance *Instance, url string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *pwd) InstanceUploadFromReader(instance *Instance, fileName string, reader io.Reader) error {
|
||||||
|
defer observeAction("InstanceUploadFromReader", time.Now())
|
||||||
|
|
||||||
|
copyErr := p.docker.CopyToContainer(instance.Name, "/var/run/pwd/uploads", fileName, reader)
|
||||||
|
|
||||||
|
if copyErr != nil {
|
||||||
|
return fmt.Errorf("Error while uploading file [%s]. Error: %s\n", fileName, copyErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *pwd) InstanceGet(session *Session, name string) *Instance {
|
func (p *pwd) InstanceGet(session *Session, name string) *Instance {
|
||||||
defer observeAction("InstanceGet", time.Now())
|
defer observeAction("InstanceGet", time.Now())
|
||||||
return session.Instances[name]
|
return session.Instances[name]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pwd
|
package pwd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ type PWDApi interface {
|
|||||||
InstanceResizeTerminal(instance *Instance, cols, rows uint) error
|
InstanceResizeTerminal(instance *Instance, cols, rows uint) error
|
||||||
InstanceAttachTerminal(instance *Instance) error
|
InstanceAttachTerminal(instance *Instance) error
|
||||||
InstanceUploadFromUrl(instance *Instance, url string) error
|
InstanceUploadFromUrl(instance *Instance, url string) error
|
||||||
|
InstanceUploadFromReader(instance *Instance, filename string, reader io.Reader) error
|
||||||
InstanceGet(session *Session, name string) *Instance
|
InstanceGet(session *Session, name string) *Instance
|
||||||
InstanceFindByIP(ip string) *Instance
|
InstanceFindByIP(ip string) *Instance
|
||||||
InstanceFindByAlias(sessionPrefix, alias string) *Instance
|
InstanceFindByAlias(sessionPrefix, alias string) *Instance
|
||||||
|
|||||||
Reference in New Issue
Block a user