Skip to content

Commit

Permalink
Added convert parameter
Browse files Browse the repository at this point in the history
Convert file to Google Docs format on-the-fly while uploading
  • Loading branch information
feschroe committed Apr 6, 2014
1 parent bd8f531 commit f666e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ func Folder(d *gdrive.Drive, title string, parentId string, share bool) error {
}

// Upload file to drive
func Upload(d *gdrive.Drive, input io.ReadCloser, title string, parentId string, share bool, mimeType string) error {
func Upload(d *gdrive.Drive, input io.ReadCloser, title string, parentId string, share bool, mimeType string, convert bool) error {

// Use filename or 'untitled' as title if no title is specified
if title == "" {
if f, ok := input.(*os.File); ok && input != os.Stdin {
Expand All @@ -181,7 +182,11 @@ func Upload(d *gdrive.Drive, input io.ReadCloser, title string, parentId string,
}
getRate := util.MeasureTransferRate()

info, err := d.Files.Insert(f).Media(input).Do()
if convert {
fmt.Printf("Converting to Google Docs format enabled\n")
}

info, err := d.Files.Insert(f).Convert(convert).Media(input).Do()
if err != nil {
return fmt.Errorf("An error occurred uploading the document: %v\n", err)
}
Expand Down
5 changes: 3 additions & 2 deletions drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Options struct {
ParentId string `goptions:"-p, --parent, description='Parent Id of the file'"`
Share bool `goptions:"--share, description='Share uploaded file'"`
MimeType string `goptions:"--mimetype, description='The MIME type (default will try to figure it out)'"`
Convert bool `goptions:"--convert, description='File will be converted to Google Docs format'"`
} `goptions:"upload"`

Download struct {
Expand Down Expand Up @@ -104,9 +105,9 @@ func main() {
case "upload":
args := opts.Upload
if args.Stdin {
err = cli.Upload(drive, os.Stdin, args.Title, args.ParentId, args.Share, args.MimeType)
err = cli.Upload(drive, os.Stdin, args.Title, args.ParentId, args.Share, args.MimeType, args.Convert)
} else {
err = cli.Upload(drive, args.File, args.Title, args.ParentId, args.Share, args.MimeType)
err = cli.Upload(drive, args.File, args.Title, args.ParentId, args.Share, args.MimeType, args.Convert)
}

case "download":
Expand Down

0 comments on commit f666e81

Please sign in to comment.