upload

package
v0.0.0-...-eb0dbd5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Incomplete = errors.New("Incomplete")

Error Incomplete returned by uploader when loaded non-last chunk.

Functions

func IdentifyMime

func IdentifyMime(file string) (string, error)

Get base mime type

$ file --mime-type pic.jpg
pic.jpg: image/jpeg

func TempFile

func TempFile() (*os.File, error)

Returns the newly created temporary file.

func TempFileChunks

func TempFileChunks(offset int64, storage, upload_sid, user_filename string) (*os.File, error)

Returns a temporary file to download chunk. To calculate a unique file name used cookie named pavo and the original file name. File located in the directory chunks storage root directory. Before returning the file pointer is shifted by the value of offset, in a situation where the pieces are loaded from the second to the last.

Types

type Body

type Body struct {
	XFile     *os.File
	Body      io.Reader
	MR        *multipart.Reader
	Available bool
}

Upload body info.

func NewBody

func NewBody(xfile string, req_body io.Reader) (*Body, error)

Check exists body in xfile and return Body.

func (*Body) Close

func (body *Body) Close() error

Close filehandler of body if XFile exists.

type Meta

type Meta struct {
	MediaType string
	Boundary  string
	Range     *Range
	Filename  string
	UploadSid string
}

Info about request headers

func ParseMeta

func ParseMeta(req *http.Request) (*Meta, error)

Parse request headers and make Meta.

type OriginalFile

type OriginalFile struct {
	BaseMime string
	Filepath string
	Filename string
	Size     int64
}

Structure describes the state of the original file.

func Process

func Process(req *http.Request, storage string) ([]*OriginalFile, error)

Downloading files from the received request. The root directory of storage, storage, used to temporarily store chunks. Returns an array of the original files and error. If you load a portion of the file, chunk, it will be stored in err error Incomplete, and in an array of a single file. File size will fit the current size.

func (*OriginalFile) Ext

func (ofile *OriginalFile) Ext() string

type Range

type Range struct {
	Start int64
	End   int64
	Size  int64
}

type Uploader

type Uploader struct {
	Root string
	Meta *Meta
	Body *Body
}

Upload manager.

func (*Uploader) Reader

func (up *Uploader) Reader() (io.Reader, string, error)

Returns the reader to read the file or chunk of request body and the original file name. If the request header Conent-Type is multipart/form-data, returns the next copy part. If all of part read the case of binary loading read the request body, an error is returned io.EOF.

func (*Uploader) SaveFile

func (up *Uploader) SaveFile() (*OriginalFile, error)

Function loads one or download the original file chunk. Asks for the starting position in the body of the request to read the next file. Asks for a temporary file. Writes data from the request body into a temporary file. Specifies the size of the resulting temporary file. If the query specified header Content-Range, and the size of the resulting file does not match, it returns an error Incomplete. Otherwise, defines the basic mime type, and returns the original file.

func (*Uploader) SaveFiles

func (up *Uploader) SaveFiles() ([]*OriginalFile, error)

Function SaveFiles sequentially loads the original files or chunk's.

func (*Uploader) TempFile

func (up *Uploader) TempFile() (*os.File, error)

Returns a temporary file to download the file or resume chunk.

func (*Uploader) Write

func (up *Uploader) Write(temp_file *os.File, body io.Reader) error

The function writes a temporary file value from reader.

Jump to

Keyboard shortcuts

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