multipart/form-data encoding module
This module provides functions that faciliate encoding name/value pairs as multipart/form-data suitable for a HTTP POST or PUT request.
multipart/form-data is the standard way to upload files over HTTP
Represents a single parameter in a multipart/form-data request
name is the name of this parameter.
If value is set, it must be a string or unicode object to use as the data for this parameter.
If filename is set, it is what to say that this parameter’s filename is. Note that this does not have to be the actual filename any local file.
If filetype is set, it is used as the Content-Type for this parameter. If unset it defaults to “text/plain; charset=utf8”
If filesize is set, it specifies the length of the file fileobj
If fileobj is set, it must be a file-like object that supports .read().
Both value and fileobj must not be set, doing so will raise a ValueError assertion.
If fileobj is set, and filesize is not specified, then the file’s size will be determined first by stat’ing fileobj‘s file descriptor, and if that fails, by seeking to the end of the file, recording the current position as the size, and then by seeking back to the beginning of the file.
Returns a new MultipartParam object constructed from the local file at filename.
filesize is determined by os.path.getsize(filename)
filetype is determined by mimetypes.guess_type(filename)[0]
filename is set to os.path.basename(filename)
Returns a list of MultipartParam objects from a sequence of name, value pairs, MultipartParam instances, or from a mapping of names to values
The values may be strings or file objects.
Returns the leading data for a multipart/form-data field that contains file data.
boundary is the boundary string used throughout a single request to separate variables.
paramname is the name of the variable in this request.
filesize is the size of the file data.
filename if specified is the filename to give to this field. This field is only useful to the server for determining the original filename.
filetype if specified is the MIME type of this file.
The actual file data should be sent after this header has been sent.
Encode params as multipart/form-data.
params should be a dictionary where the keys represent parameter names, and the values are either parameter values, or file-like objects to use as the parameter value. The file-like objects must support .read() and either .fileno() or both .seek() and .tell().
If boundary is set, then it as used as the MIME boundary. Otherwise a randomly generated boundary will be used. In either case, if the boundary string appears in the parameter values a ValueError will be raised.
Returns a tuple of datagen, headers, where datagen is a generator that will yield blocks of data that make up the encoded parameters, and headers is a dictionary with the assoicated Content-Type and Content-Length headers.