Wt
3.2.1
|
A resource which streams the data from a local file. More...
#include <Wt/WFileResource>
Public Member Functions | |
WFileResource (WObject *parent=0) | |
Default constructor. | |
WFileResource (const std::string &fileName, WObject *parent=0) | |
Creates a new resource for a file. | |
WFileResource (const std::string &mimeType, const std::string &fileName, WObject *parent=0) | |
Creates a new resource with given mime-type for a file. | |
~WFileResource () | |
Destructor. | |
void | setFileName (const std::string &fileName) |
Sets a (different) filename. | |
const std::string & | fileName () const |
Returns the filename. | |
virtual void | handleRequest (const Http::Request &request, Http::Response &response) |
Handles a request. | |
![]() | |
WStreamResource (WObject *parent=0) | |
Default constructor. | |
WStreamResource (const std::string &mimeType, WObject *parent=0) | |
Creates a new resource with given mime-type. | |
~WStreamResource () | |
Destructor. | |
void | setMimeType (const std::string &mimeType) |
Sets the mime-type. | |
const std::string & | mimeType () const |
Returns the mime-type. | |
void | setBufferSize (int size) |
Configures the buffer size. | |
int | bufferSize () const |
Returns the buffer size. | |
![]() | |
WResource (WObject *parent=0) | |
Creates a new resource. | |
~WResource () | |
Destroys the resource. | |
void | suggestFileName (const Wt::WString &name, DispositionType dispositionType=Attachment) |
Suggests a filename to the user for the data streamed by this resource. | |
const Wt::WString & | suggestedFileName () const |
Returns the suggested file name. | |
void | setDispositionType (DispositionType cd) |
Configures the Content-Disposition header. | |
DispositionType | dispositionType () const |
Returns the currently configured content disposition. | |
void | setChanged () |
Generates a new URL for this resource and emits the changed signal. | |
void | setInternalPath (const std::string &path) |
Sets an internal path for this resource. | |
std::string | internalPath () const |
Returns the internal path. | |
const std::string & | generateUrl () |
Generates an URL for this resource. | |
const std::string & | url () const |
Returns the current URL for this resource. | |
Signal & | dataChanged () |
Signal emitted when the data presented in this resource has changed. | |
void | setUploadProgress (bool enabled) |
Indicate interest in upload progress. | |
Signal< ::uint64_t,::uint64_t > & | dataReceived () |
Signal emitted when data has been received for this resource. | |
void | write (std::ostream &out, const Http::ParameterMap ¶meters=Http::ParameterMap(), const Http::UploadedFileMap &files=Http::UploadedFileMap()) |
Stream the resource to a stream. | |
void | haveMoreData () |
Indicate that more data is available. | |
![]() | |
WObject (WObject *parent=0) | |
Create a WObject with a given parent object. | |
virtual | ~WObject () |
Destructor. | |
virtual const std::string | id () const |
Returns the (unique) identifier for this object. | |
void | setObjectName (const std::string &name) |
Sets an object name. | |
virtual std::string | objectName () const |
Returns the object name. | |
void | resetLearnedSlots () |
Resets learned stateless slot implementations. | |
template<class T > | |
void | resetLearnedSlot (void(T::*method)()) |
Resets a learned stateless slot implementation. | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)()) |
Declares a slot to be stateless and learn client-side behaviour on first invocation. | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
Declares a slot to be stateless and learn client-side behaviour in advance. | |
template<class T > | |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
Provides a JavaScript implementation for a method. | |
void | addChild (WObject *child) |
Adds a child object. | |
virtual void | removeChild (WObject *child) |
Removes a child object. | |
const std::vector< WObject * > & | children () const |
Returns the children. | |
WObject * | parent () const |
Returns the parent object. |
Additional Inherited Members | |
![]() | |
enum | DispositionType { NoDisposition, Attachment, Inline } |
Values for the disposition type in the Content-Disposition header. More... | |
![]() | |
void | handleRequestPiecewise (const Http::Request &request, Http::Response &response, std::istream &input) |
Handles a request and streams the data from a std::istream. | |
![]() | |
static WObject * | sender () |
Returns the sender of the current slot call. |
A resource which streams the data from a local file.
To update the resource, either use setFileName() to point it to a new file, or emit the WResource::dataChanged() signal when only the file contents has changed, but not the filename.
The resource makes use of continuations to transmit data piecewise, without blocking a thread or requiring the entire file to be read in memory. The size of the buffer can be changed using setBufferSize().
Usage examples:
Wt::WFileResource::WFileResource | ( | WObject * | parent = 0 | ) |
Default constructor.
You need to set a file name (and mime type) for the resource using setFileName() and setMimeType().
Wt::WFileResource::WFileResource | ( | const std::string & | fileName, |
WObject * | parent = 0 |
||
) |
Creates a new resource for a file.
The mime type defaults to "text/plain".
Wt::WFileResource::~WFileResource | ( | ) |
Destructor.
It is up to the user to make sure that the resource is no longer in use (by e.g. a WImage).
|
virtual |
Handles a request.
Reimplement this method so that a proper response is generated for the given request. From the request
object you can access request parameters and whether the request is a continuation request. In the response
object, you should set the mime type and stream the output data.
A request may also concern a continuation, indicated in Http::Request::continuation(), in which case the next part for a previously created continuation should be served.
While handling a request, which may happen at any time together with event handling, the library makes sure that the resource is not being concurrently deleted, but multiple requests may happend simultaneously for a single resource.
Implements Wt::WResource.
void Wt::WFileResource::setFileName | ( | const std::string & | fileName | ) |
Sets a (different) filename.
Set the location of the file on the local filesystem which must be streamed for this resource.