aboutsummaryrefslogtreecommitdiff
path: root/go/operation/upload_content.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-02-26 22:54:22 -0800
committerChris Lu <chris.lu@gmail.com>2013-02-26 22:54:22 -0800
commitdb8e27be6ec7daa1a188f90f61e385c04cb6b008 (patch)
tree33e53b6ec51157709bc6121adeb8b19fe668c79b /go/operation/upload_content.go
parentbd278337db4e3c1937f2d7cd1623ee9627c77619 (diff)
downloadseaweedfs-db8e27be6ec7daa1a188f90f61e385c04cb6b008.tar.xz
seaweedfs-db8e27be6ec7daa1a188f90f61e385c04cb6b008.zip
add lots of error checking by GThomas
Diffstat (limited to 'go/operation/upload_content.go')
-rw-r--r--go/operation/upload_content.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go
index 0bdb697da..cae657b2c 100644
--- a/go/operation/upload_content.go
+++ b/go/operation/upload_content.go
@@ -21,9 +21,19 @@ func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult,
body_buf := bytes.NewBufferString("")
body_writer := multipart.NewWriter(body_buf)
file_writer, err := body_writer.CreateFormFile("file", filename)
- io.Copy(file_writer, reader)
+ if err != nil {
+ log.Println("error creating form file", err)
+ return nil, err
+ }
+ if _, err = io.Copy(file_writer, reader); err != nil {
+ log.Println("error copying data", err)
+ return nil, err
+ }
content_type := body_writer.FormDataContentType()
- body_writer.Close()
+ if err = body_writer.Close(); err != nil {
+ log.Println("error closing body", err)
+ return nil, err
+ }
resp, err := http.Post(uploadUrl, content_type, body_buf)
if err != nil {
log.Println("failing to upload to", uploadUrl)