GetFileById gets a Google Drive file by its id
(id string)
| 266 | |
| 267 | // GetFileById gets a Google Drive file by its id |
| 268 | func (d *Client) GetFileById(id string) (*gdrive.File, error) { |
| 269 | client, err := d.getClient() |
| 270 | if nil != err { |
| 271 | Log.Debugf("%v", err) |
| 272 | return nil, fmt.Errorf("Could not get Google Drive client") |
| 273 | } |
| 274 | |
| 275 | file, err := client.Files. |
| 276 | Get(id). |
| 277 | Fields(fields). |
| 278 | SupportsAllDrives(true). |
| 279 | Do() |
| 280 | if nil != err { |
| 281 | Log.Debugf("%v", err) |
| 282 | return nil, fmt.Errorf("Could not get object %v from API", id) |
| 283 | } |
| 284 | |
| 285 | // getting file size |
| 286 | if 0 == file.Size && folderMimeType != file.MimeType && shortcutMimeType != file.MimeType { |
| 287 | res, err := client.Files.Get(id).SupportsAllDrives(true).Download() |
| 288 | if nil != err { |
| 289 | Log.Debugf("%v", err) |
| 290 | return nil, fmt.Errorf("Could not get file size for object %v", id) |
| 291 | } |
| 292 | file.Size = res.ContentLength |
| 293 | } |
| 294 | |
| 295 | return file, nil |
| 296 | } |
| 297 | |
| 298 | // GetRoot gets the root node directly from the API |
| 299 | func (d *Client) GetRoot() (*APIObject, error) { |
no test coverage detected