POST ��ʽ�����㣺 Content-Type: multipart/form-data; boundary=xxx
| 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"); |
nothing calls this directly
no test coverage detected