uploader

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenNotFound = errors.New("Ctrl server return not found")
View Source
var ValidErrTooLarge = errors.New("File too large")

Functions

This section is empty.

Types

type Ctrl

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

func NewCtrl

func NewCtrl(url string) *Ctrl

func (*Ctrl) GetParams

func (c *Ctrl) GetParams(token string) (files *Files, err error)

func (*Ctrl) SetStatus

func (c *Ctrl) SetStatus(token string, params interface{}) (*http.Response, error)

func (*Ctrl) SetStatusErr

func (c *Ctrl) SetStatusErr(token string, err error) (*http.Response, error)

type Error

type Error struct {
	Code int    `json:"code,omitempty"`
	Msg  string `json:"message,omitempty"`
}

type File

type File struct {
	// name for save to anteater
	Name string `json:"name,omitempty"`
	// type - image or file
	Type string `json:"type,omitempty"`
	// field name in form
	Field string `json:"field,omitempty"`
	// validate
	Valid *Valid `json:"valid,omitempty"`
	// file state
	State *FileState `json:"state,omitempty"`

	// Only for images
	// GIF, JPG, PNG
	Format string `json:"format,omitempty"`
	// image width
	Width int `json:"width,omitempty"`
	// image height
	Height int `json:"height,omitempty"`
	// image quality (for jpg)
	Quality int `json:"quality,omitempty"`
	// need crop
	Crop bool `json:"crop,omitempty"`
	// apply optimize for images (png only)
	Optimize bool `json:"optimize,omitempty"`
}

func (*File) SetState

func (f *File) SetState(file *storage.File)

func (*File) Upload

func (f *File) Upload(tmpf *TmpFiles) (err error)

type FileState

type FileState struct {
	Uploaded bool   `json:"uploaded,omitempty"`
	Size     int64  `json:"size,omitempty"`
	Md5      string `json:"md5,omitempty"`
}

type Files

type Files []*File

func (*Files) Upload

func (fs *Files) Upload(conf *config.Config, stor *storage.Storage, r *http.Request, w http.ResponseWriter) (err error)

type Params

type Params struct {
	Response *Files `json:"response,omitempty"`
}

type StatusError

type StatusError struct {
	Error *Error `json:"error,omitempty"`
}

type StatusOk

type StatusOk struct {
	Response *Files `json:"response,omitempty"`
}

type TmpFiles

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

func (*TmpFiles) Close

func (t *TmpFiles) Close()

func (*TmpFiles) GetByField

func (t *TmpFiles) GetByField(field string) (f *temp.File, err error)

func (*TmpFiles) Result

func (t *TmpFiles) Result() map[string]*temp.File

func (*TmpFiles) SetResult

func (t *TmpFiles) SetResult(name string, file *temp.File)

type Uploader

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

func NewUploader

func NewUploader(c *config.Config, s *storage.Storage) *Uploader

func (*Uploader) TryRequest

func (u *Uploader) TryRequest(r *http.Request, w http.ResponseWriter) (status bool, err error, errCode int)

type Valid

type Valid struct {
	MaxSize   int64    `json:"max_size,omitempty"`
	MimeTypes []string `json:"mime_types,omitempty"`
}

func (*Valid) HasError

func (v *Valid) HasError(tf *temp.File) (err error)

Jump to

Keyboard shortcuts

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