CppCMS
|
This class holds a uploaded file, it is generally fetched via widgets::file or via http::request::files. More...
#include <cppcms/http_file.h>
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 |
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.
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
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
void cppcms::http::file::make_permanent | ( | ) |
Make sure that file created by output_file member function is not removed in destructor
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
void cppcms::http::file::save_to | ( | std::string const & | filename | ) |
Save file to file named filename. Throws cppcms_error in case of failure.
Notes:
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
void cppcms::http::file::set_temporary_directory | ( | std::string const & | dir | ) |
Set the temporary directory where uploaded files are created
long long cppcms::http::file::size | ( | ) |
Get the size of the file.