Skip to content

Commit

Permalink
Merge pull request #114 from cappyzawa/feature/multipart
Browse files Browse the repository at this point in the history
Enable to select whether to do multipart upload or not
  • Loading branch information
vito authored Dec 18, 2018
2 parents 2bbfea5 + 7dff543 commit c00d6a8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ version numbers.

* `use_v2_signing`: *Optional.* Use signature v2 signing, useful for S3 compatible providers that do not support v4.

* `disable_multipart`: *Optional.* Disable Multipart Upload. useful for S3 compatible providers that do not support multipart upload.

### File Names

One of the following two options must be specified:
Expand Down
1 change: 1 addition & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Source struct {
InitialPath string `json:"initial_path"`
InitialContentText string `json:"initial_content_text"`
InitialContentBinary string `json:"initial_content_binary"`
DisableMultipart bool `json:"disable_multipart"`
}

func (source Source) IsValid() (bool, string) {
Expand Down
1 change: 1 addition & 0 deletions out/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (command *Command) Run(sourceDir string, request Request) (Response, error)
options.ContentType = request.Params.ContentType
options.ServerSideEncryption = request.Source.ServerSideEncryption
options.KmsKeyId = request.Source.SSEKMSKeyId
options.DisableMultipart = request.Source.DisableMultipart

versionID, err := command.s3client.UploadFile(
bucketName,
Expand Down
23 changes: 23 additions & 0 deletions out/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,28 @@ var _ = Describe("Out Command", func() {
Ω(options.ContentType).Should(Equal(""))
})
})

Context("when specifying disable multipart upload", func() {
It("uploads to the parent directory without multipart upload", func() {
request.Params.File = "my/special-file.tgz"
request.Source.Regexp = "a-folder/some-file-(.*).tgz"
request.Source.DisableMultipart = true
createFile("my/special-file.tgz")

response, err := command.Run(sourceDir, request)
Expect(err).ToNot(HaveOccurred())
Ω(s3client.UploadFileCallCount()).Should(Equal(1))

bucketName, remotePath, localPath, options := s3client.UploadFileArgsForCall(0)
Expect(bucketName).To(Equal("bucket-name"))
Expect(remotePath).To(Equal("a-folder/special-file.tgz"))
Expect(localPath).To(Equal(filepath.Join(sourceDir, "my/special-file.tgz")))
Ω(options).Should(Equal(s3resource.UploadFileOptions{Acl: "private", DisableMultipart: true}))

Expect(response.Metadata[0].Name).To(Equal("filename"))
Expect(response.Metadata[0].Value).To(Equal("special-file.tgz"))
})
})

})
})
23 changes: 15 additions & 8 deletions s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type UploadFileOptions struct {
ServerSideEncryption string
KmsKeyId string
ContentType string
DisableMultipart bool
}

func NewUploadFileOptions() UploadFileOptions {
Expand Down Expand Up @@ -184,15 +185,21 @@ func (client *s3client) UploadFile(bucketName string, remotePath string, localPa
}

defer localFile.Close()

// Automatically adjust partsize for larger files.
fSize := stat.Size()
if fSize > int64(uploader.MaxUploadParts) * uploader.PartSize {
partSize := fSize / int64(uploader.MaxUploadParts)
if fSize % int64(uploader.MaxUploadParts) != 0 {
partSize++
if !options.DisableMultipart {
if fSize > int64(uploader.MaxUploadParts)*uploader.PartSize {
partSize := fSize / int64(uploader.MaxUploadParts)
if fSize%int64(uploader.MaxUploadParts) != 0 {
partSize++
}
uploader.PartSize = partSize
}
uploader.PartSize = partSize
} else {
uploader.MaxUploadParts = 1
uploader.Concurrency = 1
uploader.PartSize = fSize + 1
}

progress := client.newProgressBar(fSize)
Expand Down Expand Up @@ -385,8 +392,8 @@ func (client *s3client) getVersionedBucketContents(bucketName string, prefix str
for {

params := &s3.ListObjectVersionsInput{
Bucket: aws.String(bucketName),
Prefix: aws.String(prefix),
Bucket: aws.String(bucketName),
Prefix: aws.String(prefix),
}

if keyMarker != "" {
Expand Down

0 comments on commit c00d6a8

Please sign in to comment.