aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/pkg
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-09-20 17:58:29 -0700
committerChris Lu <chris.lu@gmail.com>2012-09-20 17:58:29 -0700
commit5e97179d061fd885ab5df0d91c1713a5139ca112 (patch)
tree125f4d7900509d09eed08a57dc969a64cef77767 /weed-fs/src/pkg
parent7d8e9f829c11dd8151144e20506e673d2f3b9d27 (diff)
downloadseaweedfs-5e97179d061fd885ab5df0d91c1713a5139ca112.tar.xz
seaweedfs-5e97179d061fd885ab5df0d91c1713a5139ca112.zip
refactoring content uploading
Diffstat (limited to 'weed-fs/src/pkg')
-rw-r--r--weed-fs/src/pkg/operation/lookup_volume_id.go (renamed from weed-fs/src/pkg/operation/lookup.go)0
-rw-r--r--weed-fs/src/pkg/operation/upload_content.go40
-rw-r--r--weed-fs/src/pkg/storage/store.go3
3 files changed, 43 insertions, 0 deletions
diff --git a/weed-fs/src/pkg/operation/lookup.go b/weed-fs/src/pkg/operation/lookup_volume_id.go
index 720286c31..720286c31 100644
--- a/weed-fs/src/pkg/operation/lookup.go
+++ b/weed-fs/src/pkg/operation/lookup_volume_id.go
diff --git a/weed-fs/src/pkg/operation/upload_content.go b/weed-fs/src/pkg/operation/upload_content.go
new file mode 100644
index 000000000..83e20bf3b
--- /dev/null
+++ b/weed-fs/src/pkg/operation/upload_content.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
+}
diff --git a/weed-fs/src/pkg/storage/store.go b/weed-fs/src/pkg/storage/store.go
index d1155bb78..4f7e66ef0 100644
--- a/weed-fs/src/pkg/storage/store.go
+++ b/weed-fs/src/pkg/storage/store.go
@@ -135,6 +135,9 @@ func (s *Store) Read(i VolumeId, n *Needle) (int, error) {
}
return 0, errors.New("Not Found")
}
+func (s *Store) GetVolume(i VolumeId) *Volume {
+ return s.volumes[i]
+}
func (s *Store) HasVolume(i VolumeId) bool {
_, ok := s.volumes[i]