aboutsummaryrefslogtreecommitdiffstats
path: root/drive/upload.go
diff options
context:
space:
mode:
Diffstat (limited to 'drive/upload.go')
-rw-r--r--drive/upload.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/drive/upload.go b/drive/upload.go
index 5c5e38e..03cb5ad 100644
--- a/drive/upload.go
+++ b/drive/upload.go
@@ -8,7 +8,6 @@ import (
"path/filepath"
"google.golang.org/api/googleapi"
"google.golang.org/api/drive/v3"
- "golang.org/x/net/context"
)
type UploadFileArgs struct {
@@ -20,9 +19,14 @@ type UploadFileArgs struct {
Recursive bool
Share bool
NoProgress bool
+ ChunkSize int64
}
func (self *Drive) Upload(args UploadFileArgs) (err error) {
+ if args.ChunkSize > intMax() - 1 {
+ return fmt.Errorf("Chunk size is to big, max chunk size for this computer is %d", intMax() - 1)
+ }
+
srcFile, err := os.Open(args.Path)
if err != nil {
return fmt.Errorf("Failed to open file: %s", err)
@@ -53,7 +57,10 @@ func (self *Drive) Upload(args UploadFileArgs) (err error) {
// Set parent folders
dstFile.Parents = args.Parents
- f, err := self.service.Files.Create(dstFile).ResumableMedia(context.Background(), srcFile, srcFileInfo.Size(), dstFile.MimeType).Do()
+ // Chunk size option
+ chunkSize := googleapi.ChunkSize(int(args.ChunkSize))
+
+ f, err := self.service.Files.Create(dstFile).Media(srcFile, chunkSize).Do()
if err != nil {
return fmt.Errorf("Failed to upload file: %s", err)
}