Namespace: go.std.mime.multipart
v1.0Contents
Summary
Provides a low-level interface to the mime/multipart package.
Package multipart implements MIME multipart parsing, as defined in RFC
2046.
The implementation is sufficient for HTTP (RFC 2388) and the multipart
bodies generated by popular browsers.
# Limits
To protect against malicious inputs, this package sets limits on the size
of the MIME data it processes.
Reader.NextPart and Reader.NextRawPart limit the number of headers in a
part to 10000 and Reader.ReadForm limits the total number of headers in all
FileHeaders to 10000.
These limits may be adjusted with the GODEBUG=multipartmaxheaders=<values>
setting.
Reader.ReadForm further limits the number of parts in a form to 1000.
This limit may be adjusted with the GODEBUG=multipartmaxparts=<value>
setting.
Copyright 2023 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
Index
- *FileHeader
- *Form
- *Part
- *Reader
- *Writer
- ErrMessageTooLarge
- File
- FileHeader
- Form
- NewReader
- NewWriter
- Part
- Reader
- Writer
- arrayOfFile
- arrayOfFileHeader
- arrayOfForm
- arrayOfPart
- arrayOfReader
- arrayOfWriter
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
ErrMessageTooLarge
Var v1.0ErrMessageTooLarge is returned by ReadForm if the message form
data is too large to be processed.
Functions, Macros, and Special Forms
-
NewReader
Function v1.0(NewReader r boundary)
NewReader creates a new multipart Reader reading from r using the
given MIME boundary.
The boundary is usually obtained from the "boundary" parameter of
the message's "Content-Type" header. Use mime.ParseMediaType to
parse such headers.
Go input arguments: (r io.Reader, boundary string)
Go returns: *Reader
Joker input arguments: [^go.std.io/Reader r, ^String boundary]
Joker returns: ^*Reader -
NewWriter
Function v1.0(NewWriter w)
NewWriter returns a new multipart Writer with a random boundary,
writing to w.
Go input arguments: (w io.Writer)
Go returns: *Writer
Joker input arguments: [^go.std.io/Writer w]
Joker returns: ^*Writer
Types
-
*FileHeader
Concrete Type v1.0A FileHeader describes a file part of a multipart request.
-
Open
Receiver for *FileHeader v1.0([])
Open opens and returns the FileHeader's associated File.
-
*Form
Concrete Type v1.0Form is a parsed multipart form.
Its File parts are stored either in memory or on disk,
and are accessible via the *FileHeader's Open method.
Its Value parts are stored as strings.
Both are keyed by field name.
-
RemoveAll
Receiver for *Form v1.0([])
RemoveAll removes any temporary files associated with a Form.
-
*Part
Concrete Type v1.0A Part represents a single part in a multipart body.
-
Close
Receiver for *Part v1.0([])
-
FileName
Receiver for *Part v1.0([])
FileName returns the filename parameter of the Part's Content-Disposition
header. If not empty, the filename is passed through filepath.Base (which is
platform dependent) before being returned.
-
FormName
Receiver for *Part v1.0([])
FormName returns the name parameter if p has a Content-Disposition
of type "form-data". Otherwise it returns the empty string.
-
Read
Receiver for *Part v1.0([d])
Read reads the body of a part, after its headers and before the
next part (if any) begins.
-
*Reader
Concrete Type v1.0Reader is an iterator over parts in a MIME multipart body.
Reader's underlying parser consumes its input as needed. Seeking
isn't supported.
-
NextPart
Receiver for *Reader v1.0([])
NextPart returns the next part in the multipart or an error.
When there are no more parts, the error io.EOF is returned.
As a special case, if the "Content-Transfer-Encoding" header
has a value of "quoted-printable", that header is instead
hidden and the body is transparently decoded during Read calls.
-
NextRawPart
Receiver for *Reader v1.0([])
NextRawPart returns the next part in the multipart or an error.
When there are no more parts, the error io.EOF is returned.
Unlike NextPart, it does not have special handling for
"Content-Transfer-Encoding: quoted-printable".
-
ReadForm
Receiver for *Reader v1.0([maxMemory])
ReadForm parses an entire multipart message whose parts have
a Content-Disposition of "form-data".
It stores up to maxMemory bytes + 10MB (reserved for non-file parts)
in memory. File parts which can't be stored in memory will be stored on
disk in temporary files.
It returns ErrMessageTooLarge if all non-file parts can't be stored in
memory.
-
*Writer
Concrete Type v1.0A Writer generates multipart messages.
-
Boundary
Receiver for *Writer v1.0([])
Boundary returns the Writer's boundary.
-
Close
Receiver for *Writer v1.0([])
Close finishes the multipart message and writes the trailing
boundary end line to the output.
-
CreateFormField
Receiver for *Writer v1.0([fieldname])
CreateFormField calls CreatePart with a header using the
given field name.
-
CreateFormFile
Receiver for *Writer v1.0([fieldname filename])
CreateFormFile is a convenience wrapper around CreatePart. It creates
a new form-data header with the provided field name and file name.
-
CreatePart
Receiver for *Writer v1.0([header])
CreatePart creates a new multipart section with the provided
header. The body of the part should be written to the returned
Writer. After calling CreatePart, any previous part may no longer
be written to.
-
FormDataContentType
Receiver for *Writer v1.0([])
FormDataContentType returns the Content-Type for an HTTP
multipart/form-data with this Writer's Boundary.
-
SetBoundary
Receiver for *Writer v1.0([boundary])
SetBoundary overrides the Writer's default randomly-generated
boundary separator with an explicit value.
SetBoundary must be called before any parts are created, may only
contain certain ASCII characters, and must be non-empty and
at most 70 bytes long.
-
WriteField
Receiver for *Writer v1.0([fieldname value])
WriteField calls CreateFormField and then writes the given value.
-
File
Abstract Type v1.0File is an interface to access the file part of a multipart message.
Its contents may be either stored in memory or on disk.
If stored on disk, the File's underlying concrete type will be an *os.File.
-
Close
Method for File v1.0([])
-
Read
Method for File v1.0([p])
-
ReadAt
Method for File v1.0([p off])
-
Seek
Method for File v1.0([offset whence])
-
FileHeader
Concrete Type v1.0A FileHeader describes a file part of a multipart request.
-
Form
Concrete Type v1.0Form is a parsed multipart form.
Its File parts are stored either in memory or on disk,
and are accessible via the *FileHeader's Open method.
Its Value parts are stored as strings.
Both are keyed by field name.
-
Part
Concrete Type v1.0A Part represents a single part in a multipart body.
-
Reader
Concrete Type v1.0Reader is an iterator over parts in a MIME multipart body.
Reader's underlying parser consumes its input as needed. Seeking
isn't supported.
-
Writer
Concrete Type v1.0A Writer generates multipart messages.
-
arrayOfFile
Concrete Type v1.0File is an interface to access the file part of a multipart message.
Its contents may be either stored in memory or on disk.
If stored on disk, the File's underlying concrete type will be an *os.File.
-
arrayOfFileHeader
Concrete Type v1.0A FileHeader describes a file part of a multipart request.
-
arrayOfForm
Concrete Type v1.0Form is a parsed multipart form.
Its File parts are stored either in memory or on disk,
and are accessible via the *FileHeader's Open method.
Its Value parts are stored as strings.
Both are keyed by field name.
-
arrayOfPart
Concrete Type v1.0A Part represents a single part in a multipart body.
-
arrayOfReader
Concrete Type v1.0Reader is an iterator over parts in a MIME multipart body.
Reader's underlying parser consumes its input as needed. Seeking
isn't supported.
-
arrayOfWriter
Concrete Type v1.0A Writer generates multipart messages.