Skip to content

Commit

Permalink
Fix content-length for PutObject() request
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed May 4, 2015
1 parent 50d802c commit 056c97d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
19 changes: 9 additions & 10 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strconv"
)

type api struct {
Expand Down Expand Up @@ -129,11 +128,11 @@ func (a *api) listObjectsRequest(bucket string, maxkeys int, marker, prefix, del
HTTPMethod: "GET",
HTTPPath: "/" + bucket + resourceQuery(),
}
req, err := NewRequest(op, a.config, nil)
r, err := NewRequest(op, a.config, nil)
if err != nil {
return nil, err
}
return req, nil
return r, nil
}

/// Bucket Read Operations
Expand Down Expand Up @@ -235,12 +234,12 @@ func (a *api) putObjectRequest(bucket, object string, size int64, body io.ReadSe
if err != nil {
return nil, err
}
req, err := NewRequest(op, a.config, ioutil.NopCloser(body))
r, err := NewRequest(op, a.config, ioutil.NopCloser(body))
if err != nil {
return nil, err
}
req.Set("Content-MD5", md5Sum)
req.Set("Content-Length", strconv.FormatInt(size, 10))
r.Set("Content-MD5", md5Sum)
r.req.ContentLength = size
return req, nil
}

Expand Down Expand Up @@ -271,18 +270,18 @@ func (a *api) getObjectRequest(bucket, object string, offset, length uint64) (*R
HTTPMethod: "GET",
HTTPPath: "/" + bucket + "/" + object,
}
req, err := NewRequest(op, a.config, nil)
r, err := NewRequest(op, a.config, nil)
if err != nil {
return nil, err
}
// TODO - fix this to support full - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
switch {
case length > 0:
req.Set("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1))
r.Set("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1))
default:
req.Set("Range", fmt.Sprintf("bytes=%d-", offset))
r.Set("Range", fmt.Sprintf("bytes=%d-", offset))
}
return req, nil
return r, nil
}

// GetObject - retrieve object from Object Storage
Expand Down
66 changes: 66 additions & 0 deletions examples/play/list_buckets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// +build ignore

/*
* Minimal object storage library (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"fmt"
"log"

"github.com/minio-io/objectstorage-go"
)

func main() {
config := new(objectstorage.Config)
config.Endpoint = "https://s3.amazonaws.com"
config.AccessKeyID = ""
config.SecretAccessKey = ""
config.UserAgent = "Minio"
m := objectstorage.New(config)

err := m.PutBucket("testbucket")
if err != nil {
log.Println(err)
}

err = m.PutBucketACL("testbucket", "public-read")
if err != nil {
log.Println(err)
}

err = m.PutBucketACL("testbucket", "invalid")
if err != nil {
log.Println(err)
}

err = m.HeadBucket("testbucket")
if err != nil {
log.Println(err)
}

listAllMyBucketsResult, err := m.ListBuckets()
if err != nil {
log.Println(err)
}
if err == nil {
buckets := listAllMyBucketsResult.Buckets
for _, bucket := range buckets.Bucket {
fmt.Println(bucket)
}
}
}
File renamed without changes.

0 comments on commit 056c97d

Please sign in to comment.