5.12Class Uploaded

Entity storing uploaded file data.

Class Uploaded

Forms containing uploadable files are returned in the Request.posts dictionary. In those forms, the entries coresponding to uploaded files are stored as instances of this class.

The class has support to access the temporary storage where the uploaded file has been placed, to read it in memory or to access the memory where the system has stored it.

For more informations read the upload_control entry.

Properties
data Complete content of the file, as a byte-sized MemBuf.
filename The name of the original file before upload.
mimeType The declared mime type of the uploaded data.
size The size of the uploaded file, in bytes.
storage Complete path to an accessible file in the local filesystem.
Methods
openOpens a read-only Falcon Stream pointing to the uploaed file.
readReads an uploaded file from the temporary storage into memory.
storeStores the uploaded data into a file.

Properties

data

Complete content of the file, as a byte-sized MemBuf.

Complete content of the file, as a byte-sized MemBuf. If the server was setup to store the file in memory as it is received, this field will be valorized with a MemBuf containing all the data in the file. If this option is not enabled, the property will be nil.

filename

The name of the original file before upload.

The name of the original file before upload. Can be used as an hint of the name it should be given locally, or for extra confirmation of the mime type.

mimeType

The declared mime type of the uploaded data.

The declared mime type of the uploaded data. This is Determined by the remote browser uploading the file, so it cannot be trusted.

size

The size of the uploaded file, in bytes.

The size of the uploaded file, in bytes.

storage

Complete path to an accessible file in the local filesystem.

Complete path to an accessible file in the local filesystem. This is where the server has temporarily stored the file. It may be destroeyd as soon as the script is closed. If the file was impored directly in memory, this field will be nil.

Methods

open

Opens a read-only Falcon Stream pointing to the uploaed file.

Uploaded.open()
ReturnA Falcon stream.
Raise
IoError on open or write error.
TypeError if the storage property is not a valid filename.

If data is filled, this method creates a memory read-only StringStream accessing the data as a file. If it was stored in a temporary file named as reported by the storage property, that file is open in read-only/shared mode.

This method allows to obtain a valid readable stream no matter if the uploaded file was cached in memory or temporarily stored to disk.

read

Reads an uploaded file from the temporary storage into memory.

Uploaded.read()
ReturnTrue if the file was actually read, false if it was already stored in memory.
Raise
IoError on read error.
TypeError if the storage property is not a valid filename.

If the uploaded file coresponding to this entry was stored in a temporary local file (in the storage property), this method reads it in a wide-enough MemBuf and stores it in the data property.

It is possible to use this method to make sure that the whole file is in the data property after a size check.

Note: The server may prevent this operation to be completed if the file is too large. Where in doubt, prefer Uploaded.open, which has the same semantic but that is more flexible and resource-aware.

store

Stores the uploaded data into a file.

Uploaded.store( path )
path The location where to store the file, or an open stream.
Raise
IoError on read or write error.
TypeError if the storage property is not a valid filename.

If data is filled, this method saves its contents into the file indicated by the path parameter; if it was stored to a temporary file, a system file move is tried, if it fails, a file copy is tried, and the origin file is removed after the copy is succesful.

On failure, a relevant IoError is raised, but the operation doesn't fail in case the original file cannot be deleted.

Note: This method can be also used to move or copy an arbitrary file by storing a path directly in the storage property.

Made with http://www.falconpl.org