multipart_requests

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: MIT Imports: 7 Imported by: 0

README

Multipart Requests

Http multipart form data requests

Install
go get -u github.com/joegasewicz/multipart-requests
Usage

Upload the file as multipart form data within a http request

m := multipart_requests.MultipartRequest{
    TempPath: "uploads", // Default is temp
    Persist:  true, // Default is false
	Url:      "http://127.0.0.1:8000/example", // Required
    Debug:    true, // Default is false
}
// If a file is being obtained via a form request then use this helper
fileName, file, err := m.GetFile(r, "logo")
// Upload the file as multipart form data within a http request
_, err = m.Upload(file,  *fileName, "logo")

Documentation

Index

Constants

View Source
const DEFAULT_METHOD = "POST"

Variables

This section is empty.

Functions

This section is empty.

Types

type MultipartRequest

type MultipartRequest struct {
	// The path where temporary files will be stored on the server
	TempPath string
	// Whether to persist files to the server. By default, files will be removed
	Persist bool
	// Set to true to get error logs. Default is false
	Debug bool
	// The request url
	Url string
}

func (*MultipartRequest) GetFile

func (m *MultipartRequest) GetFile(r *http.Request, name string) (*string, multipart.File, error)

GetFile Gets the file from an incoming form request

func (*MultipartRequest) Upload

func (m *MultipartRequest) Upload(file multipart.File, filename, field string) (*http.Response, error)

Upload a local file via an http request as multipart formdata.

Jump to

Keyboard shortcuts

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