-
Notifications
You must be signed in to change notification settings - Fork 20
/
upload.go
33 lines (30 loc) · 969 Bytes
/
upload.go
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
package gphotos
import (
"context"
"github.com/gphotosuploader/google-photos-api-client-go/v3/media_items"
)
// Upload uploads the specified file and creates the media item
// in Google Photos.
func (c *Client) Upload(ctx context.Context, filePath string) (*media_items.MediaItem, error) {
token, err := c.Uploader.UploadFile(ctx, filePath)
if err != nil {
return nil, err
}
return c.MediaItems.Create(ctx, media_items.SimpleMediaItem{
UploadToken: token,
Filename: filePath,
})
}
// UploadToAlbum uploads the specified file and creates the media item
// in the specified album in Google Photos.
func (c *Client) UploadToAlbum(ctx context.Context, albumId string, filePath string) (*media_items.MediaItem, error) {
token, err := c.Uploader.UploadFile(ctx, filePath)
if err != nil {
return nil, err
}
item := media_items.SimpleMediaItem{
UploadToken: token,
Filename: filePath,
}
return c.MediaItems.CreateToAlbum(ctx, albumId, item)
}