httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Schaefer <joe_schae...@yahoo.com>
Subject Re: How to use apreq_body_get ?
Date Tue, 21 Dec 2010 22:43:22 GMT
The name of your form parameter is "foo", and it represents
2 uploads. apreq_body_get(req, "foo") will only return the first
one tho.  To get at them both you'll need to use the table API
(eg apreq_body(req, &t)) and walk the table with a table_do function.





----- Original Message ----
> From: Mark Songhurst <mark@songhurst.org>
> To: apreq-dev@httpd.apache.org
> Sent: Tue, December 21, 2010 5:30:33 PM
> Subject: How to use apreq_body_get ?
> 
> Hello
> 
> I'm very new to both Apache and libapreq; I'm struggling to get a  C
> based Apache module working with a multipart/form-data request, which
> is  uploading 2 files.
> 
> Given these 2 parts in my  request:
> 
> Content-Disposition: form-data; name="foo";  filename="test_file_1.txt"
> Content-Type:  application/x-thought
> 
> and
> 
> Content-Disposition: form-data;  name="foo"; filename="test_file_2.txt"
> Content-Type:  application/x-thought
> 
> 
> Please could someone advise me what string I  should place in the
> second parameter in the call to apreq_body_get()  ?
> 
> I have tried using the actual filename "test_file_1.txt" but I  get
> returned a NULL pointer from apreq_body_get()
> I've also tried using  the string "filename" but this also gives me a
> NULL pointer.
> 
> At the  end of this email I've appended the full request from my
> client, and the  handler from my Apache module.
> 
> Thanks in advance for any help or  suggestions.
> 
> Kind regards,
> Mark.
> 
> 
> 
> Here is my  multipart/form-data request, generated using the libcurl
> curl_formadd  function - please excuse the output, this is from my test
> harness client (I  can't figure out how to get Apache to dump the
> entire request in it's  logs):
> 
> 12/21/10 21:19:42.402.177 HttpClient.cpp:174 DEBUG    -
> => Send header, 215 bytes (0xd7)
> 0000: POST /thoughtupload  HTTP/1.1
> 001e: Host: logger1.st3.devel.messagelabs.com
> 0047:  Accept: */*
> 0054: Content-Length: 402
> 0069: Expect: 100-continue
> 007f:  Content-Type: multipart/form-data; boundary=--------------------
> 00bf:  --------8691e9ee9b5b
> 00d5:
> 
> 12/21/10 21:19:42.403.968  HttpClient.cpp:174 DEBUG   -
> <= Recv header, 23 bytes (0x17)
> 0000:  HTTP/1.1 100 Continue
> 
> 12/21/10 21:19:42.404.326 HttpClient.cpp:174  DEBUG   -
> => Send data, 155 bytes (0x9b)
> 0000:  ------------------------------8691e9ee9b5b
> 002c: Content-Disposition:  form-data; name="foo"; filename="test_file_
> 006c: 1.txt"
> 0074:  Content-Type: application/x-thought
> 0099:
> 
> 12/21/10 21:19:42.404.741  HttpClient.cpp:174 DEBUG   -
> => Send data, 21 bytes (0x15)
> 0000:  This is test file 1..
> 
> 12/21/10 21:19:42.405.059 HttpClient.cpp:174  DEBUG   -
> => Send data, 157 bytes (0x9d)
> 0000:
> 0002:  ------------------------------8691e9ee9b5b
> 002e: Content-Disposition:  form-data; name="foo"; filename="test_file_
> 006e: 2.txt"
> 0076:  Content-Type: application/x-thought
> 009b:
> 
> 12/21/10 21:19:42.405.488  HttpClient.cpp:174 DEBUG   -
> => Send data, 21 bytes (0x15)
> 0000:  This is test file 2..
> 
> 12/21/10 21:19:42.405.740 HttpClient.cpp:174  DEBUG   -
> => Send data, 48 bytes (0x30)
> 0000:
> 0002:  ------------------------------8691e9ee9b5b--
> 
> 12/21/10 21:19:42.444.345  HttpClient.cpp:174 DEBUG   -
> <= Recv header, 17 bytes (0x11)
> 0000:  HTTP/1.1 200 OK
> 
> 
> The handler in my Apache module is as  follows:
> 
> static int thoughtupload_handler(request_rec *r)
> {
>    if (strcmp(r->handler, "thoughtupload"))
>   {
>     return  DECLINED;
>   }
> 
>   if(strncmp(r->method, "POST", 4) ==  0)
>   {
>     apreq_handle_t *req;
>     req =  apreq_handle_apache2(r);
> 
> apr_pool_t *mp =  NULL;
> apr_pool_create(&mp, NULL);
> ap_log_rerror(APLOG_MARK,  APLOG_EMERG, APR_SUCCESS, r, "I have these
> files: %s",  apreq_params_as_string(mp, apreq_params(req, mp),  NULL,
> APREQ_JOIN_AS_IS));
> apr_pool_destroy(mp);
> 
>      apreq_param_t *param = apreq_body_get(req, "test_file_1.txt");
> 
>      if(param == NULL)
>     {
> ap_log_rerror(APLOG_MARK,  APLOG_EMERG, APR_SUCCESS, r, "NO SUCH PARAM");
>     }
>      else if(param->upload == NULL)
>      {
> ap_log_rerror(APLOG_MARK, APLOG_EMERG, APR_SUCCESS, r, "NOT  UPLOAD");
>     }
>     else
>      {
> ap_log_rerror(APLOG_MARK, APLOG_EMERG, APR_SUCCESS, r, "GOT SOME  DATA!");
>     }
>   }
> 
>   return  OK;
> }
> 
> Using this code, I get the following log output:
> 
> [Tue Dec  21 21:50:16 2010] [emerg] [client 10.191.84.1] I have these
> files:  test_file_1.txt, test_file_2.txt
> [Tue Dec 21 21:50:16 2010] [emerg] [client  10.191.84.1] NO SUCH PARAM
> 


      

Mime
View raw message