WeBWorK::Upload - store uploads securely across requests.
Given $u
, an Mojo::Upload object
my $upload = WeBWorK::Upload->store($u,
dir => $ce->{webworkDirs}->{DATA}
);
my $id = $upload->id;
my $hash = $upload->hash;
Later...
my $upload = WeBWorK::Upload->retrieve($id, $hash,
dir => $ce->{webworkDirs}->{uploadCache}
);
my $fh = $upload->fileHandle;
my $path = $upload->filePath;
# get rid of the upload -- $upload is useless after this!
$upload->dispose;
# ...or move it somewhere before disposal
$upload->disposeTo($path);
WeBWorK::Upload provides a method for securely storing uploaded files until such time as they are needed. This is useful for situations in which an upload cannot be handled by the system until some later request, such as the case where a user is not yet authenticated, and a login page must be returned. Since a file upload should not be sent back to the client and then uploaded again with the user provides his login information, some proxy must be sent in its place. WeBWorK::Upload generates a unique ID which can be used to retrieve the original file.
Uploads can be stored in an upload cache and later retrieved, given the proper ID and hash. The hash is used to confirm the authenticity of the ID.
Uploads are Mojo::Upload objects under.
Stores the Mojo::Upload $u
securely. The following keys must be defined in %options:
dir => the directory in which to store the uploaded file
Return the upload's unique ID, or an undefiend value if the upload is not valid.
Return the upload's hash, or an undefiend value if the upload is not valid.
An upload stored in the upload cache can be retrieved by supplying its ID and hash (accessible from the above id
and hash
methods, respectivly. The file can then be accessed by name or file handle, moved, and disposed of.
Retrieves the Mojo::Upload referenced by $id
and $hash
. The following keys must be defined in %options:
dir => the directory in which to store the uploaded file
Returns the original name of the uploaded file.
Return a file handle pointing to the uploaded file, or an undefiend value if the upload is not valid. Suitable for reading.
Return the path to the uploaded file, or an undefiend value if the upload is not valid.
If you use this, bear in mind that you must not dispose of the upload (either by moving or deleting the uploaded file or calling the dispose
method). If you wish to move the file, use the disposeTo
method instead.
Remove the file from the upload cache. Returns true if the upload was successfully destroyed, or an undefiend value if the upload is not valid.
Remove the file from the upload cache, and move it to $path
. Returns true if the upload was successfully moved, or an undefiend value if the upload is not valid.
Written by Sam Hathaway, sh002i at math.rochester.edu. Based on the original WeBWorK::Upload module by Dennis Lambe, Jr., malsyned at math.rochester.edu.