upload

package
v2.133.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: MIT Imports: 16 Imported by: 0

README

Static File Upload Client

Usage

Setup

Local:

c := upload.NewAPIClient("http://localhost:25100")

Remote:

c := upload.NewAPIClient("http://localhost:11850")
Uploading a file
f := io.NopCloser(strings.NewReader("File content"))
m := upload.Metadata{
    CollectionID:  &collectionID, // Collection ID is option. Leave it unset if you do not have it at upload
    FileName:      "test.txt",
    Path:          "testing/docs",
    IsPublishable: true,
    Title:         "A testing file",
    FileSizeBytes: 12,
    FileType:      "text/plain",
    License:       "MIT",
    LicenseURL:    "https://opensource.org/licenses/MIT",
}

err := c.Upload(f, m)

if err != nil {
	...
}

Notes:

Documentation

Index

Constants

View Source
const (
	MaxFileSize = chunkSize * maxChunks
)

Variables

View Source
var (
	ErrFileTooLarge  = errors.New(fmt.Sprintf("file too large, max file size: %d MB", MaxFileSize>>20))
	ErrNotAuthorized = errors.New("you are not authorized for this action")
)

Functions

This section is empty.

Types

type ChunkContext added in v2.101.0

type ChunkContext struct {
	Current int
	Total   int
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an upload API client which can be used to make requests to the server. It extends the generic healthcheck Client structure.

func NewAPIClient

func NewAPIClient(uploadAPIURL, authToken string) *Client

NewAPIClient creates a new instance of Upload Client with a given image API URL

func (*Client) Checker

func (c *Client) Checker(ctx context.Context, check *health.CheckState) error

Checker calls image api health endpoint and returns a check object to the caller.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, fileContent io.ReadCloser, metadata Metadata) error

type Metadata

type Metadata struct {
	CollectionID  *string
	FileName      string
	Path          string
	IsPublishable bool
	Title         string
	FileSizeBytes int64
	FileType      string
	License       string
	LicenseURL    string
}

Jump to

Keyboard shortcuts

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