upload

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package upload implements image upload handlers.

Index

Constants

View Source
const (
	// ErrNoSingleFile returned when does not contain single file in field 'file'
	ErrNoSingleFile = "field 'file' does not contains single item"
	// ErrIncorrectData returned when field data does not contain valid base64 encoded data
	ErrIncorrectData = "incorrect data format"
	// ErrNotImage returned when media type isn't supported by underlying image processing package
	ErrNotImage = "Unsupported media type"
	// ErrNoCTypeExt returned when filename does not contain extension and we can't get it from content type
	ErrNoCTypeExt = "File ext for content type not found"
	// ErrFmtBadDownload returned when download status != 200
	ErrFmtBadDownload = "Image download failed (%d)"

	// Base64MinCommaIndex holds minimal base64 image prefix len
	Base64MinCommaIndex = 21
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DownloadLimit int64  `long:"download_limit" default:"8" description:"External image size limit (Mb)"`
	Dir           string `long:"dir" default:"data/img" description:"Image upload destination"`
	PreviewDir    string `long:"preview_dir" default:"data/preview" description:"Preview image destination"`
	PreviewWidth  int    `long:"preview_width" default:"100" description:"Preview image width"`
	PreviewHeight int    `long:"preview_heigth" default:"100" description:"Preview image heigth"`
	UseRandomName bool   `long:"random_name" description:"Do not keep uploaded image filename"`
}

Config holds all config vars

type HTTPError

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

HTTPError holds error with HTTP status

func NewHTTPError

func NewHTTPError(status int, err error) *HTTPError

NewHTTPError returns new HTTPError

func (HTTPError) Status

func (e HTTPError) Status() int

Status returns HTTPError status

type Service

type Service struct {
	Config *Config
	Log    loggers.Contextual
	// contains filtered or unexported fields
}

Service holds upload service

func New

func New(cfg Config, log loggers.Contextual) *Service

New creates an Service object

func (Service) HandleBase64

func (srv Service) HandleBase64(data, name string) (*string, error)

HandleBase64 stores file received as base64 encoded string

func (Service) HandleMultiPart

func (srv Service) HandleMultiPart(form *multipart.Form) (*string, error)

HandleMultiPart stores image from multipart form

func (Service) HandleURL

func (srv Service) HandleURL(url string) (*string, error)

HandleURL reveives and stores image from URL

Jump to

Keyboard shortcuts

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