Class Uploaded

Entity storing uploaded file data.

class Uploaded

more...

Summary

dataComplete content of the file, as a byte-sized MemBuf.
filenameThe name of the original file before upload.
mimeTypeThe declared mime type of the uploaded data.
sizeThe size of the uploaded file, in bytes.
storageComplete path to an accessible file in the local filesystem.
open()Opens a read-only Falcon Stream pointing to the uploaed file.
read()Reads an uploaded file from the temporary storage into memory.
store()Stores the uploaded data into a file.

Detailed description

class Uploaded


Entity storing uploaded file data.

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

open()

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

Uploaded.open( )

Returns:A Falcon stream.
Raises:
IoErroron open or write error.
TypeErrorif 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( )

Returns:True if the file was actually read, false if it was already stored in memory.
Raises:
IoErroron read error.
TypeErrorif 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 )

pathThe location where to store the file, or an open stream.
Raises:
IoErroron read or write error.
TypeErrorif 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 faldoc 2.2.1