Skip to content

Commit

Permalink
add param sequential for InitiateMultipartUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
taowei.wtw committed Dec 26, 2019
1 parent f05bdcd commit a8af89a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oss/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var signKeyList = []string{"acl", "uploads", "location", "cors",
"udfId", "udfImageDesc", "udfApplication", "comp",
"udfApplicationLog", "restore", "callback", "callback-var", "qosInfo",
"policy", "stat", "encryption", "versions", "versioning", "versionId", "requestPayment",
"x-oss-request-payer"}
"x-oss-request-payer", "sequential"}

// init initializes Conn
func (conn *Conn) init(config *Config, urlMaker *urlMaker, client *http.Client) error {
Expand Down
8 changes: 7 additions & 1 deletion oss/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ import (
func (bucket Bucket) InitiateMultipartUpload(objectKey string, options ...Option) (InitiateMultipartUploadResult, error) {
var imur InitiateMultipartUploadResult
opts := addContentType(options, objectKey)
params := map[string]interface{}{}
params, _ := getRawParams(options)
_, ok := params["sequential"]
if ok {
// convert "" to nil
params["sequential"] = nil
}
params["uploads"] = nil

resp, err := bucket.do("POST", objectKey, params, opts, nil, nil)
if err != nil {
return imur, err
Expand Down
5 changes: 5 additions & 0 deletions oss/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ func PartNumberMarker(value int) Option {
return addParam("part-number-marker", strconv.Itoa(value))
}

// Sequential is an option to set sequential parameter for InitiateMultipartUpload
func Sequential() Option {
return addParam("sequential", "")
}

// DeleteObjectsQuiet false:DeleteObjects in verbose mode; true:DeleteObjects in quite mode. Default is false.
func DeleteObjectsQuiet(isQuiet bool) Option {
return addArg(deleteObjectsQuiet, isQuiet)
Expand Down
39 changes: 39 additions & 0 deletions oss/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,42 @@ func (s *OssUploadSuite) TestUploadFileWithForbidOverWrite(c *C) {

forceDeleteBucket(client, bucketName, c)
}

// TestUploadFileWithSequential
func (s *OssUploadSuite) TestUploadFileWithSequential(c *C) {
// create a bucket with default proprety
client, err := New(endpoint, accessID, accessKey)
c.Assert(err, IsNil)

bucketName := bucketNamePrefix + randLowStr(6)
err = client.CreateBucket(bucketName)
c.Assert(err, IsNil)
bucket, err := client.Bucket(bucketName)

fileName := "../sample/BingWallpaper-2015-11-07.jpg"
fileInfo, err := os.Stat(fileName)
c.Assert(err, IsNil)

objectName := objectNamePrefix + randStr(8)

var respHeader http.Header

// UploadFile with properties
options := []Option{
Sequential(),
GetResponseHeader(&respHeader),
Checkpoint(true, fileName+".cp"),
}

// Updating the file
err = bucket.UploadFile(objectName, fileName, fileInfo.Size()/2, options...)
c.Assert(err, IsNil)

respHeader, err = bucket.GetObjectDetailedMeta(objectName)
c.Assert(err, IsNil)

strMD5 := respHeader.Get("Content-MD5")
c.Assert(len(strMD5) > 0, Equals, true)

forceDeleteBucket(client, bucketName, c)
}

0 comments on commit a8af89a

Please sign in to comment.