View Source Plug.Upload (Plug v1.13.4)
A server (a GenServer
specifically) that manages uploaded files.
Uploaded files are stored in a temporary directory and removed from that directory after the process that requested the file dies.
During the request, files are represented with
a Plug.Upload
struct that contains three fields:
:path
- the path to the uploaded file on the filesystem:content_type
- the content type of the uploaded file:filename
- the filename of the uploaded file given in the request
Note: as mentioned in the documentation for Plug.Parsers
, the :plug
application has to be started in order to upload files and use the
Plug.Upload
module.
security
Security
The :content_type
and :filename
fields in the Plug.Upload
struct are
client-controlled. These values should be validated, via file content
inspection or similar, before being trusted.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Assign ownership of the given upload file to another process.
Requests a random file to be created in the upload directory with the given prefix.
Requests a random file to be created in the upload directory with the given prefix. Raises on failure.
Link to this section Types
Specs
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
Assign ownership of the given upload file to another process.
Useful if you want to do some work on an uploaded file in another process since it means that the file will survive the end of the request.
Specs
random_file(binary()) :: {:ok, binary()} | {:too_many_attempts, binary(), pos_integer()} | {:no_tmp, [binary()]}
Requests a random file to be created in the upload directory with the given prefix.
Specs
Requests a random file to be created in the upload directory with the given prefix. Raises on failure.