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

Method doUpload

lib_acl_cpp/samples/ssl/ssl_server/ssl_server.cpp:155–269  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

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