godock: github.com/sqp/godock/libs/net/upload Index | Files

package upload

import "github.com/sqp/godock/libs/net/upload"

Index

Package Files

poster.go upload.go

func File Uses

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

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

func PostForm Uses

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

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

func Reader Uses

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 Uses

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

type AsMultipart Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type AsRequestHTTP struct {
    UpBase
    Method string
}

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

func NewRequester Uses

func NewRequester(method, uri string) *AsRequestHTTP

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

func (*AsRequestHTTP) Post Uses

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 Uses

type Config struct {
    Anonymous bool
    LimitRate int
}

Config defines upload settings.

type Poster Uses

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 Uses

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 Uses

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

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

func NewBaseURL Uses

func NewBaseURL(uri string) UpBase

NewBaseURL creates an upload service base with the URI.

func (*UpBase) GetURL Uses

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

GetURL gives the service download URL for the given filename.

func (*UpBase) Name Uses

func (sb *UpBase) Name() string

Name returns the service text name.

func (*UpBase) SetConfig Uses

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

SetConfig sets the service config pointer to the backend.

func (*UpBase) SetName Uses

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 Uses

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

UpBaser provides configuraton to the Poster.

Package upload imports 8 packages (graph) and is imported by 1 packages. Updated 2016-08-23. Refresh now. Tools for package owners.