#include <Wt/WFileUpload>
Public Slots | |
void | upload () |
Start the file upload. | |
Public Member Functions | |
WFileUpload (WContainerWidget *parent=0) | |
Construct a file upload widget. | |
void | setFileTextSize (int chars) |
Set the size of the file input. | |
int | fileTextSize () const |
Get the size of the file input. | |
const std::string & | spoolFileName () const |
Get the spooled location of the uploaded file. | |
const WString & | clientFileName () const |
Get the client filename. | |
const WString & | contentDescription () const |
Get the client content description. | |
void | stealSpooledFile () |
Steal the spooled file. | |
bool | emptyFileName () const |
Check if no filename was given and thus no file uploaded. | |
bool | isUploaded () const |
Returns whether the upload() slot will trigger a new upload. | |
Public Attributes | |
Signal< void > | uploaded |
Signal emitted when a new file was uploaded. | |
Signal< int > | fileTooLarge |
Signal emitted when the user tried to upload a too large file. | |
EventSignal< void > | changed |
Signal emitted when the user selected a new file. | |
Protected Member Functions | |
virtual void | htmlText (std::ostream &out) |
Stream the (X)HTML representation. |
This widget is displayed as a box in which a filename can be entered and a browse button.
Depending on availability of JavaScript, the behaviour of the widget is different, but the API is designed in a way which facilitates a portable use.
When JavaScript is available, the file will not be uploaded until upload() is called. This will start an asynchronous upload (and thus return immediately). When the file has been uploaded, the uploaded signal is emitted, or if the file was too large, the fileTooLarge signal is emitted.
When no JavaScript is available, the file will be uploaded with the next click event. Thus, upload() is not useful -- the file will already be uploaded, and the corresponding signals will already be emitted. To test if upload() is needed, you may check using the isUploaded() call.
Thus, to properly use the widget, one needs to follow these rules:
The WFileUpload widget must be hidden or deleted when a file is received. In addition it is wise to prevent the user from uploading the file twice.
The uploaded file is automatically spooled to a local temporary file which will be deleted together with the WFileUpload widget, unless stealSpooledFile() is called.
const std::string& Wt::WFileUpload::spoolFileName | ( | ) | const [inline] |
Get the spooled location of the uploaded file.
Returns the temporary filename in which the uploaded file was spooled. The file is guaranteed to exist as long as the WFileUpload widget is not deleted, or a new file is not uploaded.
void Wt::WFileUpload::stealSpooledFile | ( | ) |
Steal the spooled file.
By stealing the file, the spooled file will no longer be deleted together with this widget, which means you need to take care of managing that.
bool Wt::WFileUpload::emptyFileName | ( | ) | const [inline] |
Check if no filename was given and thus no file uploaded.
Return whether a non-empty filename was given.
void Wt::WFileUpload::upload | ( | ) | [slot] |
Start the file upload.
The uploaded signal is emitted when a file is uploaded, or the WFileUpload::fileTooLarge signal is emitted when the file size exceeded the maximum request size.
void Wt::WFileUpload::htmlText | ( | std::ostream & | out | ) | [protected, virtual] |
Stream the (X)HTML representation.
Streams the widget as UTF8-encoded (HTML-compatible) XHTML.
This may be useful as a debugging tool for the web-savvy, or in other rare situations. Usually, you will not deal directly with HTML, and calling this method on a widget that is rendered may interfere with the library keeping track of changes to the widget.
Reimplemented from Wt::WWidget.
Signal emitted when a new file was uploaded.
This signal is emitted when a new file has been received. It is good practice to hide or delete the WFileUpload widget when a file has been uploaded succesfully.
Signal emitted when the user selected a new file.
One could react on the user selecting a (new) file, by uploading the file immediately.
Caveat: this signal is not emitted with konqueror and possibly other browsers. Thus, in the above scenario you should still provide an alternative way to call the upload() method.