CppCMS
Public Member Functions | Friends | List of all members
cppcms::http::file Class Reference

This class holds a uploaded file, it is generally fetched via widgets::file or via http::request::files. More...

#include <cppcms/http_file.h>

Inheritance diagram for cppcms::http::file:
booster::noncopyable

Public Member Functions

std::string name () const
 
std::string mime () const
 
bool has_mime () const
 
std::string filename () const
 
std::istream & data ()
 
long long size ()
 
void output_file (std::string const &name, bool is_temporary=false)
 
void make_permanent ()
 
int close ()
 
void save_to (std::string const &filename)
 
void set_memory_limit (size_t size)
 
void set_temporary_directory (std::string const &dir)
 

Friends

class request
 

Detailed Description

This class holds a uploaded file, it is generally fetched via widgets::file or via http::request::files.

It provides full information about uploaded data as it was send by browser and allows to read the file via std::istream seek-able interface or save to the file system

Note: this class does not perform any validations, for checking the data use widgets::file that allows to perform numerous checks on the file data.

Member Function Documentation

int cppcms::http::file::close ( )

Close the file if it is still open, if the file temporary it is deleted, the the file in memory its content is removed, data() would return non-usable stream

Returns 0 in case of sucess and -1 in case of failure

New in CppCMS 1.2

std::istream& cppcms::http::file::data ( )

Get std::istream on the data, please note, you need to call data().seekg(0) when using this stream first time.

std::string cppcms::http::file::filename ( ) const

Get the filename as it was sent by the browser.

bool cppcms::http::file::has_mime ( ) const

Returns true if content type defined

New in CppCMS 1.2

void cppcms::http::file::make_permanent ( )

Make sure that file created by output_file member function is not removed in destructor

New in CppCMS 1.2

std::string cppcms::http::file::mime ( ) const

Get the content-type of the file as it was sent by the browser.

std::string cppcms::http::file::name ( ) const

Get the name of the POST field (i.e. <input name="value" ...>)

void cppcms::http::file::output_file ( std::string const &  name,
bool  is_temporary = false 
)

Specify the path to the output file, note if is_temporary is true than the file would be deleted on cppcms::http::file destruction, unless save_to is called, otherwise it would remain persistent

New in CppCMS 1.2

void cppcms::http::file::save_to ( std::string const &  filename)

Save file to file named filename. Throws cppcms_error in case of failure.

Notes:

  • this function maybe more efficient then just reading the stream and writing it to newly created file, as in case of big files, it would try to move it over the file system
  • Under Win32 filename should be UTF-8 string
void cppcms::http::file::set_memory_limit ( size_t  size)

Set the maximal size of file that would be stored in memory instead of file system

New in CppCMS 1.2

void cppcms::http::file::set_temporary_directory ( std::string const &  dir)

Set the temporary directory where uploaded files are created

New in CppCMS 1.2

long long cppcms::http::file::size ( )

Get the size of the file.


The documentation for this class was generated from the following file: