MCPcopy Create free account
hub / github.com/acl-dev/acl / doUpload

Method doUpload

lib_acl_cpp/samples/cgi_upload/main.cpp:147–267  ·  view source on GitHub ↗

POST ��ʽ�����㣺 Content-Type: multipart/form-data; boundary=xxx

Source from the content-addressed store, hash-verified

145 // POST ��ʽ�����㣺
146 // Content-Type: multipart/form-data; boundary=xxx
147 bool doUpload(HttpServletRequest& req, HttpServletResponse& res)
148 {
149 // �Ȼ�� Content-Type ��Ӧ�� http_ctype ����
150 http_mime* mime = req.getHttpMime();
151 if (mime == NULL)
152 {
153 logger_error("http_mime null");
154 return false;
155 }
156
157 // ���������ij���
158 long long int len = req.getContentLength();
159 if (len <= 0)
160 {
161 logger_error("body empty");
162 return false;
163 }
164
165 // ���������
166 istream& in = req.getInputStream();
167 char buf[8192];
168 int ret;
169 bool finish = false;
170
171 const char* filepath = "./var/mime_file";
172 ofstream out;
173 out.open_write(filepath);
174
175 // ����ԭʼ�ļ�����·��
176 mime->set_saved_path(filepath);
177
178 size_t k;
179
180 // ��ȡ HTTP �ͻ�����������
181 while (len > 0)
182 {
183 k = (size_t) len > sizeof(buf)
184 ? sizeof(buf) : (size_t) len;
185 ret = in.read(buf, k, false);
186 if (ret == -1)
187 {
188 logger_error("read POST data error");
189 return false;
190 }
191 out.write(buf, ret);
192
193 len -= ret;
194
195 // �����õ����������������������н���
196 if (!finish && mime->update(buf, ret) == true)
197 finish = true;
198 }
199 out.close();
200
201 if (len != 0 || finish == false)
202 logger_warn("not read all data from client");
203
204 param1_ = req.getParameter("name1");

Callers

nothing calls this directly

Calls 15

acl_safe_basenameFunction · 0.85
getHttpMimeMethod · 0.80
getContentLengthMethod · 0.80
set_saved_pathMethod · 0.80
getParameterMethod · 0.80
beginMethod · 0.80
get_mime_typeMethod · 0.80
open_writeMethod · 0.45
readMethod · 0.45
writeMethod · 0.45
updateMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected