uploader

package
v3.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUploadNotFound    = errors.New("upload not found")
	ErrFingerprintNotSet = errors.New("fingerprint not set")
)

Functions

This section is empty.

Types

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HttpClient represent a client to make an HTTP request. It is usually implemented by net/http.Client.

type ResumableUploader

type ResumableUploader struct {

	// Base URL for API requests.
	// BaseURL should always be specified with a trailing slash.
	BaseURL string

	// Logger used to log messages.
	Logger log.Logger

	// Store maps an upload's fingerprint with the corresponding upload URL.
	Store Store
	// contains filtered or unexported fields
}

ResumableUploader implements resumable uploads.

See: https://developers.google.com/photos/library/guides/resumable-uploads.

func NewResumableUploader

func NewResumableUploader(httpClient HttpClient) (*ResumableUploader, error)

NewResumableUploader returns a new client to upload files to Google Photos with resumable capabilities. API methods require authentication, provide an net/http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*ResumableUploader) IsResumeEnabled

func (u *ResumableUploader) IsResumeEnabled() bool

func (*ResumableUploader) UploadFile

func (u *ResumableUploader) UploadFile(ctx context.Context, filePath string) (uploadToken string, err error)

UploadFile returns the Google Photos upload token after uploading a file. Any non-2xx status code is an error. Response headers are in error.(*googleapi.Error).Header.

type SimpleUploader

type SimpleUploader struct {

	// Base URL for API requests.
	// BaseURL should always be specified with a trailing slash.
	BaseURL string

	// Logger used to log messages.
	Logger log.Logger
	// contains filtered or unexported fields
}

SimpleUploader implements a simple uploader to Google Photos.

func NewSimpleUploader

func NewSimpleUploader(httpClient HttpClient) (*SimpleUploader, error)

NewSimpleUploader returns a new client to upload files to Google Photos. API methods require authentication, provide an net/http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*SimpleUploader) UploadFile

func (u *SimpleUploader) UploadFile(ctx context.Context, filePath string) (uploadToken string, err error)

UploadFile uploads a file to Google Photos using upload request. A successful upload request returns an upload token. Use this upload token to create a media item with [media_items.Create].

type Store

type Store interface {
	Get(fingerprint string) (string, bool)
	Set(fingerprint string, url string)
	Delete(fingerprint string)
	Close()
}

Store represents a service to map upload's fingerprint with the corresponding upload URL.

type Upload

type Upload struct {
	Name        string
	Fingerprint string
	// contains filtered or unexported fields
}

func NewUpload

func NewUpload(reader io.Reader, size int64, name string, fingerprint string) *Upload

NewUpload creates a new upload from an io.Reader.

func NewUploadFromFile

func NewUploadFromFile(f *os.File) (*Upload, error)

NewUploadFromFile creates a new Upload from an os.File.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL