httpfile

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2017 License: MIT Imports: 11 Imported by: 5

README

httpfile

Build Status Coverage Status License GoDoc

Features

  • Upload multi file by formdata
  • Upload file by stream
  • Custom file Content-Type for upload
  • Support add extra field to formdata
  • Download file

Installation

go get github.com/mushroomsir/httpfile

Usage

package main

import "github.com/mushroomsir/httpfile"
import "fmt"

func main() {
	res, err := httpfile.Upload(httpfile.UploadOptions{
		FileItems: httpfile.NewFileItems("test.gif"),
		TargetURL: "TargetURL",
	})

	fmt.Println(err)
	fmt.Println(res)
}

Licenses

All source code is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Head(targetURL string, Header ...map[string]string) (*http.Response, error)

Head ...

Types

type DownloadResponse

type DownloadResponse struct {
	Res        *http.Response
	FileSize   int64
	Header     http.Header
	StatusCode int
}

DownloadResponse ...

func Download

func Download(targetURL string, savePath string, Header ...map[string]string) (*DownloadResponse, error)

Download will get filename from 'Content-Disposition' if savePath is empty.

type FileItem

type FileItem struct {
	FilePath string
	// application/octet-stream by default
	ContentType string
}

FileItem ...

func NewFileItem

func NewFileItem(filePath string, contentType ...string) FileItem

NewFileItem ...

func NewFileItems

func NewFileItems(filePath string, contentType ...string) []FileItem

NewFileItems ...

type HTTPFile

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

HTTPFile ...

func New

func New(client *http.Client) *HTTPFile

New ...

func (*HTTPFile) Download

func (h *HTTPFile) Download(targetURL string, savePath string, Header ...map[string]string) (*DownloadResponse, error)

Download will get filename from 'Content-Disposition' if savePath is empty.

func (*HTTPFile) Head

func (h *HTTPFile) Head(targetURL string, Header ...map[string]string) (*http.Response, error)

Head ...

func (*HTTPFile) Upload

func (h *HTTPFile) Upload(opts UploadOptions) (*UploadResponse, error)

Upload ...

func (*HTTPFile) UploadFile

func (h *HTTPFile) UploadFile(filePath string, targetURL string, Header ...map[string]string) (*UploadResponse, error)

UploadFile ...

func (*HTTPFile) UploadReader

func (h *HTTPFile) UploadReader(body io.Reader, targetURL string, Header ...map[string]string) (*UploadResponse, error)

UploadReader ...

type UploadOptions

type UploadOptions struct {
	FileItems []FileItem
	TargetURL string
	Header    map[string]string
	// file by default
	FileField  string
	ExtraField map[string]string
	Stream     bool
}

UploadOptions ...

type UploadResponse

type UploadResponse struct {
	Res        *http.Response
	Result     []byte
	Header     http.Header
	StatusCode int
}

UploadResponse ...

func Upload

func Upload(opts UploadOptions) (*UploadResponse, error)

Upload single or multi file to file server by formdata

func UploadFile

func UploadFile(filePath string, targetURL string, Header ...map[string]string) (*UploadResponse, error)

UploadFile ...

func UploadReader

func UploadReader(body io.Reader, targetURL string, Header ...map[string]string) (*UploadResponse, error)

UploadReader ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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