Chris Lu
12 years ago
6 changed files with 74 additions and 47 deletions
-
3weed-fs/note/replication.txt
-
51weed-fs/src/cmd/weed/upload.go
-
24weed-fs/src/cmd/weed/volume.go
-
0weed-fs/src/pkg/operation/lookup_volume_id.go
-
40weed-fs/src/pkg/operation/upload_content.go
-
3weed-fs/src/pkg/storage/store.go
@ -0,0 +1,40 @@ |
|||
package operation |
|||
|
|||
import ( |
|||
"bytes" |
|||
"encoding/json" |
|||
"mime/multipart" |
|||
"net/http" |
|||
_ "fmt" |
|||
"io" |
|||
"io/ioutil" |
|||
) |
|||
|
|||
type UploadResult struct { |
|||
Size int |
|||
} |
|||
|
|||
func Upload(server string, fid 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) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
defer resp.Body.Close() |
|||
resp_body, err := ioutil.ReadAll(resp.Body) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
var ret UploadResult |
|||
err = json.Unmarshal(resp_body, &ret) |
|||
if err != nil { |
|||
panic(err.Error()) |
|||
} |
|||
//fmt.Println("Uploaded " + strconv.Itoa(ret.Size) + " Bytes to " + uploadUrl)
|
|||
return &ret, nil |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue