Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

MIME type on upload #9

Merged
merged 2 commits into from

2 participants

@nova77

Can specify a custom MIME type on upload.

@prasmussen prasmussen merged commit d9b1ad5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2014
  1. @nova77
  2. @nova77

    Uppercase MIME

    nova77 authored
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +5 −2 cli/cli.go
  2. +3 −2 drive.go
View
7 cli/cli.go
@@ -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)
View
5 drive.go
@@ -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":
Something went wrong with that request. Please try again.