1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
|
// Package drive provides access to the Drive API.
//
// See https://developers.google.com/drive/
//
// Usage example:
//
// import "google.golang.org/api/drive/v1"
// ...
// driveService, err := drive.New(oauthHttpClient)
package drive
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"golang.org/x/net/context"
"google.golang.org/api/googleapi"
"io"
"net/http"
"net/url"
"strconv"
"strings"
)
// Always reference these packages, just in case the auto-generated code
// below doesn't.
var _ = bytes.NewBuffer
var _ = strconv.Itoa
var _ = fmt.Sprintf
var _ = json.NewDecoder
var _ = io.Copy
var _ = url.Parse
var _ = googleapi.Version
var _ = errors.New
var _ = strings.Replace
var _ = context.Background
const apiId = "drive:v1"
const apiName = "drive"
const apiVersion = "v1"
const basePath = "https://www.googleapis.com/drive/v1/"
// OAuth2 scopes used by this API.
const (
// View and manage Google Drive files that you have opened or created
// with this app
DriveFileScope = "https://www.googleapis.com/auth/drive.file"
)
func New(client *http.Client) (*Service, error) {
if client == nil {
return nil, errors.New("client is nil")
}
s := &Service{client: client, BasePath: basePath}
s.Files = NewFilesService(s)
return s, nil
}
type Service struct {
client *http.Client
BasePath string // API endpoint base URL
UserAgent string // optional additional User-Agent fragment
Files *FilesService
}
func (s *Service) userAgent() string {
if s.UserAgent == "" {
return googleapi.UserAgent
}
return googleapi.UserAgent + " " + s.UserAgent
}
func NewFilesService(s *Service) *FilesService {
rs := &FilesService{s: s}
return rs
}
type FilesService struct {
s *Service
}
type File struct {
// CreatedDate: Create time for this file (formatted RFC 3339
// timestamp).
CreatedDate string `json:"createdDate,omitempty"`
// Description: A short description of the file
Description string `json:"description,omitempty"`
// DownloadUrl: Short term download URL for the file. This will only be
// populated on files with content stored in Drive.
DownloadUrl string `json:"downloadUrl,omitempty"`
// Etag: ETag of the file.
Etag string `json:"etag,omitempty"`
// FileExtension: The file extension used when downloading this file.
// This field is read only. To set the extension, include it on title
// when creating the file. This will only be populated on files with
// content stored in Drive.
FileExtension string `json:"fileExtension,omitempty"`
// FileSize: The size of the file in bytes. This will only be populated
// on files with content stored in Drive.
FileSize int64 `json:"fileSize,omitempty,string"`
// Id: The id of the file.
Id string `json:"id,omitempty"`
// IndexableText: Indexable text attributes for the file (can only be
// written)
IndexableText *FileIndexableText `json:"indexableText,omitempty"`
// Kind: The type of file. This is always drive#file
Kind string `json:"kind,omitempty"`
// Labels: Labels for the file.
Labels *FileLabels `json:"labels,omitempty"`
// LastViewedDate: Last time this file was viewed by the user (formatted
// RFC 3339 timestamp).
LastViewedDate string `json:"lastViewedDate,omitempty"`
// Md5Checksum: An MD5 checksum for the content of this file. This will
// only be populated on files with content stored in Drive.
Md5Checksum string `json:"md5Checksum,omitempty"`
// MimeType: The mimetype of the file
MimeType string `json:"mimeType,omitempty"`
// ModifiedByMeDate: Last time this file was modified by the user
// (formatted RFC 3339 timestamp).
ModifiedByMeDate string `json:"modifiedByMeDate,omitempty"`
// ModifiedDate: Last time this file was modified by anyone (formatted
// RFC 3339 timestamp).
ModifiedDate string `json:"modifiedDate,omitempty"`
// ParentsCollection: Collection of parent folders which contain this
// file.
// On insert, setting this field will put the file in all of the
// provided folders. If no folders are provided, the file will be placed
// in the default root folder. On update, this field is ignored.
ParentsCollection []*FileParentsCollection `json:"parentsCollection,omitempty"`
// SelfLink: A link back to this file.
SelfLink string `json:"selfLink,omitempty"`
// Title: The title of this file.
Title string `json:"title,omitempty"`
// UserPermission: The permissions for the authenticated user on this
// file.
UserPermission *Permission `json:"userPermission,omitempty"`
}
type FileIndexableText struct {
// Text: The text to be indexed for this file
Text string `json:"text,omitempty"`
}
type FileLabels struct {
// Hidden: Whether this file is hidden from the user
Hidden bool `json:"hidden,omitempty"`
// Starred: Whether this file is starred by the user.
Starred bool `json:"starred,omitempty"`
// Trashed: Whether this file has been trashed.
Trashed bool `json:"trashed,omitempty"`
}
type FileParentsCollection struct {
// Id: The id of this parent
Id string `json:"id,omitempty"`
// ParentLink: A link to get the metadata for this parent
ParentLink string `json:"parentLink,omitempty"`
}
type Permission struct {
// AdditionalRoles: Any additional roles that this permission describes.
AdditionalRoles []string `json:"additionalRoles,omitempty"`
// Etag: An etag for this permission.
Etag string `json:"etag,omitempty"`
// Kind: The kind of this permission. This is always drive#permission
Kind string `json:"kind,omitempty"`
// Role: The role that this permission describes. (For example: reader,
// writer, owner)
Role string `json:"role,omitempty"`
// Type: The type of permission (For example: user, group etc).
Type string `json:"type,omitempty"`
}
// method id "drive.files.get":
type FilesGetCall struct {
s *Service
id string
opt_ map[string]interface{}
}
// Get: Gets a file's metadata by id.
func (r *FilesService) Get(id string) *FilesGetCall {
c := &FilesGetCall{s: r.s, opt_: make(map[string]interface{})}
c.id = id
return c
}
// Projection sets the optional parameter "projection": This parameter
// is deprecated and has no function.
//
// Possible values:
// "BASIC" - Deprecated
// "FULL" - Deprecated
func (c *FilesGetCall) Projection(projection string) *FilesGetCall {
c.opt_["projection"] = projection
return c
}
// UpdateViewedDate sets the optional parameter "updateViewedDate":
// Whether to update the view date after successfully retrieving the
// file.
func (c *FilesGetCall) UpdateViewedDate(updateViewedDate bool) *FilesGetCall {
c.opt_["updateViewedDate"] = updateViewedDate
return c
}
// Fields allows partial responses to be retrieved.
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
func (c *FilesGetCall) Fields(s ...googleapi.Field) *FilesGetCall {
c.opt_["fields"] = googleapi.CombineFields(s)
return c
}
func (c *FilesGetCall) Do() (*File, error) {
var body io.Reader = nil
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["projection"]; ok {
params.Set("projection", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateViewedDate"]; ok {
params.Set("updateViewedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
urls += "?" + params.Encode()
req, _ := http.NewRequest("GET", urls, body)
googleapi.Expand(req.URL, map[string]string{
"id": c.id,
})
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Gets a file's metadata by id.",
// "httpMethod": "GET",
// "id": "drive.files.get",
// "parameterOrder": [
// "id"
// ],
// "parameters": {
// "id": {
// "description": "The id for the file in question.",
// "location": "path",
// "required": true,
// "type": "string"
// },
// "projection": {
// "description": "This parameter is deprecated and has no function.",
// "enum": [
// "BASIC",
// "FULL"
// ],
// "enumDescriptions": [
// "Deprecated",
// "Deprecated"
// ],
// "location": "query",
// "type": "string"
// },
// "updateViewedDate": {
// "default": "true",
// "description": "Whether to update the view date after successfully retrieving the file.",
// "location": "query",
// "type": "boolean"
// }
// },
// "path": "files/{id}",
// "response": {
// "$ref": "File"
// },
// "scopes": [
// "https://www.googleapis.com/auth/drive.file"
// ]
// }
}
// method id "drive.files.insert":
type FilesInsertCall struct {
s *Service
file *File
opt_ map[string]interface{}
media_ io.Reader
resumable_ googleapi.SizeReaderAt
mediaType_ string
ctx_ context.Context
protocol_ string
}
// Insert: Inserts a file, and any settable metadata or blob content
// sent with the request.
func (r *FilesService) Insert(file *File) *FilesInsertCall {
c := &FilesInsertCall{s: r.s, opt_: make(map[string]interface{})}
c.file = file
return c
}
// Media specifies the media to upload in a single chunk.
// At most one of Media and ResumableMedia may be set.
func (c *FilesInsertCall) Media(r io.Reader) *FilesInsertCall {
c.media_ = r
c.protocol_ = "multipart"
return c
}
// ResumableMedia specifies the media to upload in chunks and can be cancelled with ctx.
// At most one of Media and ResumableMedia may be set.
// mediaType identifies the MIME media type of the upload, such as "image/png".
// If mediaType is "", it will be auto-detected.
func (c *FilesInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *FilesInsertCall {
c.ctx_ = ctx
c.resumable_ = io.NewSectionReader(r, 0, size)
c.mediaType_ = mediaType
c.protocol_ = "resumable"
return c
}
// ProgressUpdater provides a callback function that will be called after every chunk.
// It should be a low-latency function in order to not slow down the upload operation.
// This should only be called when using ResumableMedia (as opposed to Media).
func (c *FilesInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *FilesInsertCall {
c.opt_["progressUpdater"] = pu
return c
}
// Fields allows partial responses to be retrieved.
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
func (c *FilesInsertCall) Fields(s ...googleapi.Field) *FilesInsertCall {
c.opt_["fields"] = googleapi.CombineFields(s)
return c
}
func (c *FilesInsertCall) Do() (*File, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.SetOpaque(req.URL)
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
UserAgent: c.s.userAgent(),
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return nil, err
}
defer res.Body.Close()
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Inserts a file, and any settable metadata or blob content sent with the request.",
// "httpMethod": "POST",
// "id": "drive.files.insert",
// "mediaUpload": {
// "accept": [
// "*/*"
// ],
// "maxSize": "5120GB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/drive/v1/files"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/drive/v1/files"
// }
// }
// },
// "path": "files",
// "request": {
// "$ref": "File"
// },
// "response": {
// "$ref": "File"
// },
// "scopes": [
// "https://www.googleapis.com/auth/drive.file"
// ],
// "supportsMediaUpload": true
// }
}
// method id "drive.files.patch":
type FilesPatchCall struct {
s *Service
id string
file *File
opt_ map[string]interface{}
}
// Patch: Updates file metadata and/or content. This method supports
// patch semantics.
func (r *FilesService) Patch(id string, file *File) *FilesPatchCall {
c := &FilesPatchCall{s: r.s, opt_: make(map[string]interface{})}
c.id = id
c.file = file
return c
}
// NewRevision sets the optional parameter "newRevision": Whether a blob
// upload should create a new revision. If false, the blob data in the
// current head revision is replaced. If true or not set, a new blob is
// created as head revision, and previous revisions are preserved
// (causing increased use of the user's data storage quota).
func (c *FilesPatchCall) NewRevision(newRevision bool) *FilesPatchCall {
c.opt_["newRevision"] = newRevision
return c
}
// UpdateModifiedDate sets the optional parameter "updateModifiedDate":
// Controls updating the modified date of the file. If true, the
// modified date will be updated to the current time, regardless of
// whether other changes are being made. If false, the modified date
// will only be updated to the current time if other changes are also
// being made (changing the title, for example).
func (c *FilesPatchCall) UpdateModifiedDate(updateModifiedDate bool) *FilesPatchCall {
c.opt_["updateModifiedDate"] = updateModifiedDate
return c
}
// UpdateViewedDate sets the optional parameter "updateViewedDate":
// Whether to update the view date after successfully updating the file.
func (c *FilesPatchCall) UpdateViewedDate(updateViewedDate bool) *FilesPatchCall {
c.opt_["updateViewedDate"] = updateViewedDate
return c
}
// Fields allows partial responses to be retrieved.
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
func (c *FilesPatchCall) Fields(s ...googleapi.Field) *FilesPatchCall {
c.opt_["fields"] = googleapi.CombineFields(s)
return c
}
func (c *FilesPatchCall) Do() (*File, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["newRevision"]; ok {
params.Set("newRevision", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateModifiedDate"]; ok {
params.Set("updateModifiedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateViewedDate"]; ok {
params.Set("updateViewedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
urls += "?" + params.Encode()
req, _ := http.NewRequest("PATCH", urls, body)
googleapi.Expand(req.URL, map[string]string{
"id": c.id,
})
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Updates file metadata and/or content. This method supports patch semantics.",
// "httpMethod": "PATCH",
// "id": "drive.files.patch",
// "parameterOrder": [
// "id"
// ],
// "parameters": {
// "id": {
// "description": "The id for the file in question.",
// "location": "path",
// "required": true,
// "type": "string"
// },
// "newRevision": {
// "default": "true",
// "description": "Whether a blob upload should create a new revision. If false, the blob data in the current head revision is replaced. If true or not set, a new blob is created as head revision, and previous revisions are preserved (causing increased use of the user's data storage quota).",
// "location": "query",
// "type": "boolean"
// },
// "updateModifiedDate": {
// "default": "false",
// "description": "Controls updating the modified date of the file. If true, the modified date will be updated to the current time, regardless of whether other changes are being made. If false, the modified date will only be updated to the current time if other changes are also being made (changing the title, for example).",
// "location": "query",
// "type": "boolean"
// },
// "updateViewedDate": {
// "default": "true",
// "description": "Whether to update the view date after successfully updating the file.",
// "location": "query",
// "type": "boolean"
// }
// },
// "path": "files/{id}",
// "request": {
// "$ref": "File"
// },
// "response": {
// "$ref": "File"
// },
// "scopes": [
// "https://www.googleapis.com/auth/drive.file"
// ]
// }
}
// method id "drive.files.update":
type FilesUpdateCall struct {
s *Service
id string
file *File
opt_ map[string]interface{}
media_ io.Reader
resumable_ googleapi.SizeReaderAt
mediaType_ string
ctx_ context.Context
protocol_ string
}
// Update: Updates file metadata and/or content
func (r *FilesService) Update(id string, file *File) *FilesUpdateCall {
c := &FilesUpdateCall{s: r.s, opt_: make(map[string]interface{})}
c.id = id
c.file = file
return c
}
// NewRevision sets the optional parameter "newRevision": Whether a blob
// upload should create a new revision. If false, the blob data in the
// current head revision is replaced. If true or not set, a new blob is
// created as head revision, and previous revisions are preserved
// (causing increased use of the user's data storage quota).
func (c *FilesUpdateCall) NewRevision(newRevision bool) *FilesUpdateCall {
c.opt_["newRevision"] = newRevision
return c
}
// UpdateModifiedDate sets the optional parameter "updateModifiedDate":
// Controls updating the modified date of the file. If true, the
// modified date will be updated to the current time, regardless of
// whether other changes are being made. If false, the modified date
// will only be updated to the current time if other changes are also
// being made (changing the title, for example).
func (c *FilesUpdateCall) UpdateModifiedDate(updateModifiedDate bool) *FilesUpdateCall {
c.opt_["updateModifiedDate"] = updateModifiedDate
return c
}
// UpdateViewedDate sets the optional parameter "updateViewedDate":
// Whether to update the view date after successfully updating the file.
func (c *FilesUpdateCall) UpdateViewedDate(updateViewedDate bool) *FilesUpdateCall {
c.opt_["updateViewedDate"] = updateViewedDate
return c
}
// Media specifies the media to upload in a single chunk.
// At most one of Media and ResumableMedia may be set.
func (c *FilesUpdateCall) Media(r io.Reader) *FilesUpdateCall {
c.media_ = r
c.protocol_ = "multipart"
return c
}
// ResumableMedia specifies the media to upload in chunks and can be cancelled with ctx.
// At most one of Media and ResumableMedia may be set.
// mediaType identifies the MIME media type of the upload, such as "image/png".
// If mediaType is "", it will be auto-detected.
func (c *FilesUpdateCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *FilesUpdateCall {
c.ctx_ = ctx
c.resumable_ = io.NewSectionReader(r, 0, size)
c.mediaType_ = mediaType
c.protocol_ = "resumable"
return c
}
// ProgressUpdater provides a callback function that will be called after every chunk.
// It should be a low-latency function in order to not slow down the upload operation.
// This should only be called when using ResumableMedia (as opposed to Media).
func (c *FilesUpdateCall) ProgressUpdater(pu googleapi.ProgressUpdater) *FilesUpdateCall {
c.opt_["progressUpdater"] = pu
return c
}
// Fields allows partial responses to be retrieved.
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
func (c *FilesUpdateCall) Fields(s ...googleapi.Field) *FilesUpdateCall {
c.opt_["fields"] = googleapi.CombineFields(s)
return c
}
func (c *FilesUpdateCall) Do() (*File, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["newRevision"]; ok {
params.Set("newRevision", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateModifiedDate"]; ok {
params.Set("updateModifiedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateViewedDate"]; ok {
params.Set("updateViewedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("PUT", urls, body)
googleapi.Expand(req.URL, map[string]string{
"id": c.id,
})
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
UserAgent: c.s.userAgent(),
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return nil, err
}
defer res.Body.Close()
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Updates file metadata and/or content",
// "httpMethod": "PUT",
// "id": "drive.files.update",
// "mediaUpload": {
// "accept": [
// "*/*"
// ],
// "maxSize": "5120GB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/drive/v1/files/{id}"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/drive/v1/files/{id}"
// }
// }
// },
// "parameterOrder": [
// "id"
// ],
// "parameters": {
// "id": {
// "description": "The id for the file in question.",
// "location": "path",
// "required": true,
// "type": "string"
// },
// "newRevision": {
// "default": "true",
// "description": "Whether a blob upload should create a new revision. If false, the blob data in the current head revision is replaced. If true or not set, a new blob is created as head revision, and previous revisions are preserved (causing increased use of the user's data storage quota).",
// "location": "query",
// "type": "boolean"
// },
// "updateModifiedDate": {
// "default": "false",
// "description": "Controls updating the modified date of the file. If true, the modified date will be updated to the current time, regardless of whether other changes are being made. If false, the modified date will only be updated to the current time if other changes are also being made (changing the title, for example).",
// "location": "query",
// "type": "boolean"
// },
// "updateViewedDate": {
// "default": "true",
// "description": "Whether to update the view date after successfully updating the file.",
// "location": "query",
// "type": "boolean"
// }
// },
// "path": "files/{id}",
// "request": {
// "$ref": "File"
// },
// "response": {
// "$ref": "File"
// },
// "scopes": [
// "https://www.googleapis.com/auth/drive.file"
// ],
// "supportsMediaUpload": true
// }
}
|