upload

package
v0.0.0-...-0caaa62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(method, url, file string) (string, error)

File creates a new http PUT request with the given file path.

func PostForm

func PostForm(url string, values url.Values) (string, error)

PostForm creates a new http POST request with optional extra params.

func Reader

func Reader(method, url string, r io.Reader, size int64) (string, error)

Reader creates a new http request with the given reader and method (PUT / POST).

func ReaderMultipart

func ReaderMultipart(url, fileref, filename string, limitRate int, rdr io.Reader, size int64, params map[string]string) (string, error)

ReaderMultipart creates a new http multipart POST upload request with optional extra params.

Thanks to https://gist.github.com/mattetti/5914158/f4d1393d83ebedc682a3c8e7bdc6b49670083b84

Types

type AsMultipart

type AsMultipart struct {
	UpBase
	FileRef string                                   // Field used by the site as file name source.
	Options map[string]string                        // Needed site options with other fields values.
	PrePost func(hm *AsMultipart, file string) error // Optional call before the Post.
}

AsMultipart implements a Poster with multipart POST.

func NewMultiparter

func NewMultiparter(uri, fileRef string, args ...string) *AsMultipart

NewMultiparter creates a http multipart Poster with the given fields. Args must be provided by pairs of key, value.

func (*AsMultipart) Post

func (m *AsMultipart) Post(r io.Reader, size int64, file string) (string, error)

Post send content to the hosting service and return the parsed result.

type AsPostFormHTTP

type AsPostFormHTTP struct {
	UpBase
	ContentRef string                                          // Field used by the site as file name source.
	Options    map[string]string                               // One shot options with fields values.
	PrePost    func(hp *AsPostFormHTTP, content *string) error // Optional call before the Post.
}

AsPostFormHTTP implements a Poster with http POST form fields.

func NewPostForm

func NewPostForm(uri, fileRef string, args ...string) *AsPostFormHTTP

NewPostForm creates a form Poster with the given fields. Args must be provided by pairs of key, value.

func (*AsPostFormHTTP) Post

func (m *AsPostFormHTTP) Post(r io.Reader, size int64, file string) (string, error)

Post send content to the hosting service and return the parsed result.

Used by text backends, file may sometimes be a raw string to upload instead of a file path.

type AsRequestHTTP

type AsRequestHTTP struct {
	UpBase
	Method string
}

AsRequestHTTP implements a Poster with simple http request (POST / PUT).

func NewRequester

func NewRequester(method, uri string) *AsRequestHTTP

NewRequester creates a http request Poster with the given method (POST / GET).

func (*AsRequestHTTP) Post

func (m *AsRequestHTTP) Post(r io.Reader, size int64, file string) (string, error)

Post send content to the hosting service and return the parsed result.

type Config

type Config struct {
	Anonymous bool
	LimitRate int
}

Config defines upload settings.

type Poster

type Poster interface {
	Post(r io.Reader, size int64, filename string) (string, error)
	UpBaser
}

A Poster sends reader data to one defined hosting service.

type UpBase

type UpBase struct {
	*Config // User config.

	CallGetURL func(string) string // Default set to return a simple url.
	// contains filtered or unexported fields
}

UpBase provides the core for an upload service.

func NewBaseCB

func NewBaseCB(cb func(file string) string) UpBase

NewBaseCB creates an upload service base with the given get URI callback.

func NewBaseURL

func NewBaseURL(uri string) UpBase

NewBaseURL creates an upload service base with the URI.

func (*UpBase) GetURL

func (sb *UpBase) GetURL(file string) string

GetURL gives the service download URL for the given filename.

func (*UpBase) Name

func (sb *UpBase) Name() string

Name returns the service text name.

func (*UpBase) SetConfig

func (sb *UpBase) SetConfig(cfg *Config)

SetConfig sets the service config pointer to the backend.

func (*UpBase) SetName

func (sb *UpBase) SetName(name string)

SetName sets the service name. (Done at service init with its reference, so the text name is only referenced in the backend list)

type UpBaser

type UpBaser interface {
	SetName(name string)
	Name() string
	GetURL(file string) string
	SetConfig(*Config)
}

UpBaser provides configuraton to the Poster.

Jump to

Keyboard shortcuts

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