Help us shape the future of Go! Take the 2026 Go Developer Survey

upload

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package upload builds multipart/form-data bodies for catalog requests that send files, and the synthetic files they send when no real file is named: a minimal valid file of a kind (CSV, XLSX, PNG, PDF…), the same bytes every time, holding no data of anyone.

Index

Constants

View Source
const (
	CSV  = "csv"
	XLSX = "xlsx"
	TXT  = "txt"
	JSON = "json"
	PNG  = "png"
	JPEG = "jpeg"
	GIF  = "gif"
	PDF  = "pdf"
)

Synthetic kinds.

Variables

This section is empty.

Functions

func Encode

func Encode(fields [][2]string, files []Part) (body []byte, contentType string, err error)

Encode writes a multipart/form-data body: the fields in order, then the files. The boundary is derived from the content, so the same request is the same bytes on every capture, and it never occurs in the content. The body is written into a buffer sized for it up front, never grown.

func FileName

func FileName(kind string) string

FileName is the name a synthetic file of the kind is sent with.

func KindOf

func KindOf(nameOrExt, mediaType string) string

KindOf picks the synthetic kind that stands in for a file, from its media type or its name (an extension or a Laravel mimes: value); "" when none fits.

func Kinds

func Kinds() []string

Kinds lists the synthetic kinds.

func Known

func Known(kind string) bool

Known reports whether kind is a synthetic kind.

func MediaType

func MediaType(kind string) string

MediaType is the content type a file of the kind is sent with.

func Synthetic

func Synthetic(kind string) ([]byte, error)

Synthetic returns the synthetic file of a kind. Spreadsheets hold one header row and one row of neutral values, so an import accepts them.

Types

type Part

type Part struct {
	Field string
	Name  string // file name sent in Content-Disposition
	Type  string // Content-Type of the part
	Data  []byte
	Open  func() (io.ReadCloser, error) // when Data is nil
	Size  int64                         // of what Open gives
}

Part is one file of a multipart body: Data, or what Open gives, which is read twice (to name the boundary, then into the body), so a large file is not held besides the body.

Jump to

Keyboard shortcuts

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