Menu

[r2354]: / framework / trunk / cppcms / http_file.h  Maximize  Restore  History

Download this file

144 lines (115 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_HTTP_FILE_H
#define CPPCMS_HTTP_FILE_H
#include <cppcms/defs.h>
#include <cppcms/cstdint.h>
#include <booster/hold_ptr.h>
#include <booster/nowide/fstream.h>
#include <booster/noncopyable.h>
#include <sstream>
#include <fstream>
namespace cppcms {
/// \cond INTERNAL
namespace impl { class multipart_parser; }
/// \endcond
namespace http {
class request;
///
/// \brief 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.
///
class CPPCMS_API file : public booster::noncopyable {
public:
///
/// Get the name of the POST field (i.e. <input name="value" ...>)
///
std::string name() const;
///
/// Get the content-type of the file as it was sent by the browser.
///
std::string mime() const;
///
/// Returns true if content type defined
///
bool has_mime() const;
///
/// Get the filename as it was sent by the browser.
///
std::string filename() const;
///
/// Get std::istream on the data, please note, you need to call data().seekg(0) when using this
/// stream first time.
///
std::istream &data();
///
/// Get the size of the file.
///
long long size();
///
/// 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 output_file(std::string const &name,bool is_temporary = false);
///
/// Make sure that file created by output_file member function is not removed in destructor
///
void make_permanent();
///
/// Save file to file named \a 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 \a filename should be UTF-8 string
///
void save_to(std::string const &filename);
/// \cond INTERNAL
void name(std::string const &);
void mime(std::string const &);
void filename(std::string const &);
std::ostream &write_data();
file();
~file();
/// \endcond
///
/// Set the maximal size of file that would be stored in memory instead of file system
///
void set_memory_limit(size_t size);
///
/// Set the temporary directory where uploaded files are created
///
void set_temporary_directory(std::string const &dir);
private:
std::string name_;
std::string mime_;
std::string filename_;
size_t size_limit_;
booster::nowide::fstream res1_;
std::stringstream res2_;
std::string res3_;
std::string res4_;
void save_by_copy(std::string const &file_name,std::istream &in);
void copy_stream(std::istream &in,std::ostream &out);
uint32_t removed_ : 1 ;
uint32_t file_specified_ : 1;
uint32_t file_temporary_: 1;
uint32_t reserverd_ : 29;
struct impl_data; // for future use
booster::hold_ptr<impl_data> d;
friend class request;
};
} } //::cppcms::http
#endif
MongoDB Logo MongoDB