I have some code that is based on the following Golang example at https://developers.google.com/drive/v2/reference/files/insert.
// InsertFile creates a new file in Drive from the given file and details
func InsertFile(d *drive.Service, title string, description string,
parentId string, mimeType string, filename string) (*drive.File, error) {
.
.
.
f := &drive.File{Title: title, Description: description, MimeType: mimeType}
if parentId != "" {
p := &drive.ParentReference{Id: parentId}
f.Parents = []*drive.ParentReference{p}
}
r, err := d.Files.Insert(f).Media(m).Do()
if err != nil {
fmt.Printf("An error occurred: %v
", err)
return nil, err
}
return r, nil
}
When I switch to version 3, the errors below are thrown.
./main.go:125: unknown drive.File field 'Title' in struct literal
./main.go:127: undefined: drive.ParentReference
./main.go:128: undefined: drive.ParentReference
./main.go:131: service.Files.Insert undefined (type *drive.FilesService has no field or method Insert)
I know that Title should be changed to Name in the first error but I'm not sure what replaced drive.ParentReference or service.Files.Insert in Version 3 of the SDK and I haven't been able to find anything equivalent to the link above in the V3 docs.
It's worth perusing the Google API go source code here. You can see how ParentReference
exists in the v2 API code but does not exist in v3. The API appears to have changed significantly from v2 to v3.
Extrapolating from these changes, here's a sketch of what the v3 equivalent for uploading a file might look like:
import "google.golang.org/api/drive/v3"
func InsertFile(d *drive.Service, title string, description string, mimeType string, filename string) (*drive.File, error) {
f := &drive.File{Name: filename, Description: description, MimeType: mimeType}
return d.Files.Create(f).do()
}