Wt::WFileResource Class Reference

A Resource which streams data from a local file. More...

#include <Wt/WFileResource>

Inheritance diagram for Wt::WFileResource:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 WFileResource (const std::string &mimeType, const std::string &fileName, WObject *parent=0)
 Create a new resource with given mime-type and contents stored in filename.
 ~WFileResource ()
 Destroy the resource.
void setFileName (const std::string &fileName)
 Set a (different) filename.
const std::string & fileName () const
 Get the filename.
void setMimeType (const std::string &mimeType)
 Set the mime-type.
const std::string & mimeType () const
 Get the mime-type.
void setBufferSize (int size)
 Configure the buffer size.
int bufferSize () const
 Returns the buffer size.

Protected Member Functions

virtual void handleRequest (const Http::Request &request, Http::Response &response)
 Handle a request.


Detailed Description

A Resource which streams 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 *csvFile = new Wt::WFileResource("text/csv", "/opt/files/afile.csv");
 csvFile->suggestFileName("data.csv");
 Wt::WAnchor *anchor = new Wt::WAnchor(csvFile, "CSV data");

 Wt::WFileResource *imageFile = new Wt::WFileResource("image/png", "/opt/files/image.png");
 imageFile->suggestFileName("data.png");
 Wt::WImage *image = new Wt::WImage(imageFile, "PNG version");

See also:
WMemoryResource

Constructor & Destructor Documentation

Wt::WFileResource::~WFileResource (  ) 

Destroy the resource.

It is up to the user to make sure that the resource is nog longer in use (by e.g. a WImage).


Member Function Documentation

void Wt::WFileResource::setFileName ( const std::string &  fileName  ) 

Set a (different) filename.

Set the location of the file on the local filesystem which must be streamed for this resource.

void Wt::WFileResource::setBufferSize ( int  size  ) 

Configure the buffer size.

This configures the size of the buffer used to transmit the file piece by piece.

int Wt::WFileResource::bufferSize (  )  const [inline]

Returns the buffer size.

See also:
setBufferSize()

void Wt::WFileResource::handleRequest ( const Http::Request request,
Http::Response response 
) [protected, virtual]

Handle 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.


Generated on Mon Mar 9 08:27:51 2009 for Wt by doxygen 1.5.6