diff options
| author | Norman Casagrande | 2014-02-18 12:01:37 +0000 |
|---|---|---|
| committer | Norman Casagrande | 2014-02-18 12:01:37 +0000 |
| commit | f1f81fce96c711c6f6e59d1907966ae2418bea98 (patch) | |
| tree | cf3dc723e8a21ca3a85fb8a35b6fb3aa9bd1470b | |
| parent | 0fa147d4fb2e264ceb53521c9d0b21e322753698 (diff) | |
| download | gdrive-f1f81fce96c711c6f6e59d1907966ae2418bea98.tar.bz2 | |
Added support for mime types while uploading
| -rw-r--r-- | cli/cli.go | 7 | ||||
| -rw-r--r-- | drive.go | 5 |
2 files changed, 8 insertions, 4 deletions
@@ -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 { @@ -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) @@ -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 { @@ -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": |
