Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from nova77/mime_type
Browse files Browse the repository at this point in the history
MIME type on upload
  • Loading branch information
prasmussen committed Feb 18, 2014
2 parents 0fa147d + c59c0b2 commit d9b1ad5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cli/cli.go
Expand Up @@ -158,7 +158,7 @@ func Folder(d *gdrive.Drive, title string, parentId string, share bool) {
}

// Upload file to drive
func Upload(d *gdrive.Drive, input io.ReadCloser, title string, parentId string, share bool) {
func Upload(d *gdrive.Drive, input io.ReadCloser, title string, parentId string, share bool, mimeType string) {
// 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 @@ -168,7 +168,10 @@ func Upload(d *gdrive.Drive, input io.ReadCloser, title string, parentId string,
}
}

var mimeType = mime.TypeByExtension(filepath.Ext(title))
if mimeType == "" {
mimeType = mime.TypeByExtension(filepath.Ext(title))
}

// File instance
f := &drive.File{Title: title, MimeType: mimeType}
// Set parent (if provided)
Expand Down
5 changes: 3 additions & 2 deletions drive.go
Expand Up @@ -45,6 +45,7 @@ type Options struct {
Title string `goptions:"-t, --title, description='Title to give uploaded file. Defaults to filename'"`
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)'"`
} `goptions:"upload"`

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

case "download":
Expand Down

0 comments on commit d9b1ad5

Please sign in to comment.