|
|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
|
"golang.org/x/oauth2" |
|
|
|
|
"golang.org/x/oauth2/google" |
|
|
|
|
"google.golang.org/api/drive/v3" |
|
|
|
|
"google.golang.org/api/googleapi" |
|
|
|
|
"google.golang.org/api/option" |
|
|
|
|
"log" |
|
|
|
|
"os" |
|
|
|
@ -169,6 +170,10 @@ func main() { |
|
|
|
|
"check-token", |
|
|
|
|
false, |
|
|
|
|
"True to exit after getting the token.") |
|
|
|
|
contentType := flag.String( |
|
|
|
|
"content-type", |
|
|
|
|
"", |
|
|
|
|
"The content type to upload as. If omitted, no explicit content type is set.") |
|
|
|
|
flag.Parse() |
|
|
|
|
var dataFile *os.File |
|
|
|
|
var dataFilename string |
|
|
|
@ -219,14 +224,19 @@ func main() { |
|
|
|
|
Name: dataFilename, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var mediaOptions []googleapi.MediaOption |
|
|
|
|
if *contentType != "" { |
|
|
|
|
mediaOptions = append(mediaOptions, googleapi.ContentType(*contentType)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if *fileId != "" { |
|
|
|
|
fileOut, err := srv.Files.Update(*fileId, &metadata).Media(dataFile).Do() |
|
|
|
|
fileOut, err := srv.Files.Update(*fileId, &metadata).Media(dataFile, mediaOptions...).Do() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("Failed updating file %s: %v", *fileId, err) |
|
|
|
|
} |
|
|
|
|
fmt.Println(fileOut.Id) |
|
|
|
|
} else { |
|
|
|
|
fileOut, err := srv.Files.Create(&metadata).Media(dataFile).Do() |
|
|
|
|
fileOut, err := srv.Files.Create(&metadata).Media(dataFile, mediaOptions...).Do() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("Failed uploading file: %v", err) |
|
|
|
|
} |
|
|
|
|