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