aboutsummaryrefslogtreecommitdiff
path: root/go/operation/upload_content.go
diff options
context:
space:
mode:
authoryourchanges <yourchanges@gmail.com>2015-02-12 17:32:53 +0800
committeryourchanges <yourchanges@gmail.com>2015-02-12 17:32:53 +0800
commit2adf4a108b595ec8b4503b34665591741fa4f963 (patch)
treeda968af4fa066dfd281ae0ef4e6d59d806fed10e /go/operation/upload_content.go
parent55c40997b1cd9e33eaa841b8abf5e1678773dd1c (diff)
parenteff83a87d126faf0dd5b05876690271777f41e65 (diff)
downloadseaweedfs-2adf4a108b595ec8b4503b34665591741fa4f963.tar.xz
seaweedfs-2adf4a108b595ec8b4503b34665591741fa4f963.zip
Merge pull request #6 from chrislusf/master
merge
Diffstat (limited to 'go/operation/upload_content.go')
-rw-r--r--go/operation/upload_content.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go
index 480d76dca..533be82cb 100644
--- a/go/operation/upload_content.go
+++ b/go/operation/upload_content.go
@@ -15,6 +15,7 @@ import (
"strings"
"github.com/chrislusf/weed-fs/go/glog"
+ "github.com/chrislusf/weed-fs/go/security"
)
type UploadResult struct {
@@ -35,13 +36,13 @@ func init() {
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
-func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string) (*UploadResult, error) {
+func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string, jwt security.EncodedJwt) (*UploadResult, error) {
return upload_content(uploadUrl, func(w io.Writer) (err error) {
_, err = io.Copy(w, reader)
return
- }, filename, isGzipped, mtype)
+ }, filename, isGzipped, mtype, jwt)
}
-func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, mtype string) (*UploadResult, error) {
+func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, mtype string, jwt security.EncodedJwt) (*UploadResult, error) {
body_buf := bytes.NewBufferString("")
body_writer := multipart.NewWriter(body_buf)
h := make(textproto.MIMEHeader)
@@ -55,6 +56,9 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
if isGzipped {
h.Set("Content-Encoding", "gzip")
}
+ if jwt != "" {
+ h.Set("Authorization", "BEARER "+string(jwt))
+ }
file_writer, cp_err := body_writer.CreatePart(h)
if cp_err != nil {
glog.V(0).Infoln("error creating form file", cp_err.Error())