Franky Braem <[EMAIL PROTECTED]> writes:
> Is there a step by step tutorial on how to implement a file upload in
> an Apache module with apreq2? I'm trying to write mod_wxjs (JavaScript
> and wxWidgets as server side script, more info on
> wxjs.sourceforge.net) and I want to add a file upload functionality
> (something like php).
>
>
Something like this:
#include "httpd.h"
#include "apreq_module.h"
#include "apreq_param.h"
#include "apreq_module_apache2.h"
#include "apreq_util.h"
apreq_handle_t *req;
apreq_param_t *param;
request_rec *r;
... initialize r ...
req = apreq_handle_apache2(r);
param = apreq_body_get(req, "name of upload widget");
if (param == NULL) {
/* error: missing field */
}
else if (param->upload == NULL) {
/* error: widget not an upload */
}
else {
/* have upload field */
apr_table_t *info; /* upload headers */
apr_bucket_brigade *bb; /* upload contents */
apr_bucket_t *e;
info = param->info;
/* DO SOMETHING with info */
bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
apreq_brigade_copy(bb, param->upload);
while ((e = APR_BRIGADE_FIRST(bb)) != APR_BRIGADE_SENTINEL(bb)) {
apr_size_t dlen;
const char *data;
apr_status_t s;
/* apr_bucket_read() has side effects on spool buckets, which
* is why we read from a copy of the brigade - to conserve memory
*/
s = apr_bucket_read(e, &data, &dlen, APR_BLOCK_READ);
if (s != APR_SUCCESS) {
/* error: bad bucket read */
break;
}
else {
/* DO SOMETHING with data, dlen */
}
apr_bucket_delete(e);
}
}
--
Joe Schaefer