now any data node can accept storing files
files are automatically copied to replicas
This commit is contained in:
@@ -14,14 +14,14 @@ type UploadResult struct {
|
||||
Size int
|
||||
}
|
||||
|
||||
func Upload(server string, fid string, filename string, reader io.Reader) (*UploadResult, error) {
|
||||
func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) {
|
||||
body_buf := bytes.NewBufferString("")
|
||||
body_writer := multipart.NewWriter(body_buf)
|
||||
file_writer, err := body_writer.CreateFormFile("file", filename)
|
||||
io.Copy(file_writer, reader)
|
||||
content_type := body_writer.FormDataContentType()
|
||||
body_writer.Close()
|
||||
resp, err := http.Post("http://"+server+"/"+fid, content_type, body_buf)
|
||||
resp, err := http.Post(uploadUrl, content_type, body_buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
@@ -21,17 +22,17 @@ type Needle struct {
|
||||
Padding []byte "Aligned to 8 bytes"
|
||||
}
|
||||
|
||||
func NewNeedle(r *http.Request) (n *Needle, e error) {
|
||||
func NewNeedle(r *http.Request) (n *Needle, fname string, e error) {
|
||||
|
||||
n = new(Needle)
|
||||
form, fe := r.MultipartReader()
|
||||
if fe != nil {
|
||||
println("MultipartReader [ERROR]", fe)
|
||||
fmt.Println("MultipartReader [ERROR]", fe)
|
||||
e = fe
|
||||
return
|
||||
}
|
||||
part, _ := form.NextPart()
|
||||
fname := part.FileName()
|
||||
fname = part.FileName()
|
||||
data, _ := ioutil.ReadAll(part)
|
||||
//log.Println("uploading file " + part.FileName())
|
||||
dotIndex := strings.LastIndex(fname, ".")
|
||||
|
||||
Reference in New Issue
Block a user