Return-Path: Delivered-To: apmail-httpd-apreq-dev-archive@www.apache.org Received: (qmail 6584 invoked from network); 24 Feb 2006 14:09:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Feb 2006 14:09:27 -0000 Received: (qmail 77815 invoked by uid 500); 24 Feb 2006 14:09:25 -0000 Delivered-To: apmail-httpd-apreq-dev-archive@httpd.apache.org Received: (qmail 77784 invoked by uid 500); 24 Feb 2006 14:09:25 -0000 Mailing-List: contact apreq-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list apreq-dev@httpd.apache.org Received: (qmail 77773 invoked by uid 99); 24 Feb 2006 14:09:25 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Feb 2006 06:09:25 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of gcaa-apreq-dev@m.gmane.org designates 80.91.229.2 as permitted sender) Received: from [80.91.229.2] (HELO ciao.gmane.org) (80.91.229.2) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Feb 2006 06:09:24 -0800 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1FCdcd-0004u8-PZ for apreq-dev@httpd.apache.org; Fri, 24 Feb 2006 15:08:40 +0100 Received: from adsl-065-012-220-185.sip.bct.bellsouth.net ([65.12.220.185]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 24 Feb 2006 15:08:39 +0100 Received: from joe+gmane by adsl-065-012-220-185.sip.bct.bellsouth.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 24 Feb 2006 15:08:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: apreq-dev@httpd.apache.org To: apreq-dev@httpd.apache.org From: Joe Schaefer Subject: Re: File upload Date: Fri, 24 Feb 2006 09:08:14 -0500 Lines: 74 Message-ID: <87lkw0c0j5.fsf@gemini.sunstarsys.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: adsl-065-012-220-185.sip.bct.bellsouth.net Mail-Copies-To: never User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:Tvo3hcNigF246rBZOvARfICtQ6c= Sender: news X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Franky Braem 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