NAME

WeBWorK::Upload - store uploads securely across requests.

SYNOPSIS

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);

DESCRIPTION

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.

STORING UPLOADS

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.

CONSTRUCTOR

store($u, %options)

Stores the Mojo::Upload $u securely. The following keys must be defined in %options:

dir => the directory in which to store the uploaded file
id

Return the upload's unique ID, or an undefiend value if the upload is not valid.

hash

Return the upload's hash, or an undefiend value if the upload is not valid.

RETRIEVING UPLOADS

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.

CONSTRUCTOR

retrieve($id, $hash, %options)

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

METHODS

filename

Returns the original name of the uploaded file.

fileHandle

Return a file handle pointing to the uploaded file, or an undefiend value if the upload is not valid. Suitable for reading.

filePath

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.

dispose

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.

disposeTo($path)

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.

AUTHOR

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.