You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Whut Jia <wh...@163.com> on 2011/01/19 13:11:35 UTC

How to send a jpeg-file in Handler

Hi all,
I want to return a local jpeg-file to client when client request url is /image/metto .In handler module ,I should how to write??
Thanks,
ajxs. 

Re: Re: How to send a jpeg-file in Handler

Posted by Sorin Manolache <so...@gmail.com>.
2011/1/19 Whut  Jia <wh...@163.com>:
> Hi Sorin Manolache,
> According your ways(ap_send_fd()),it is work.The picture is returned to client.But myself-set cookie content are not returned , why??
> Begin sending jpg-file,I set a cookie in headers_out :
> r->content_type="image/jpeg";
> apr_table_setn(r->headers_out,"Set-Cookie",cookie-contence);
> ap_send_fd(fd, request, 0, file_size, &bytes_sent);
> return OK;
> Besides,the request address of the jpeg picture ishttp://www.whut.com/portal/logout.jpg. This request is sent from the response page of ahttp://www.jjsonicIDP.com/saml/logout.action request .
> Thanks,
> ajxs


I don't know why the cookie is not sent.

Try apr_table_set(r->err_headers_out, ...);

Also, are you sure that the pointer to cookie_contents is still valid
at the very end of the request processing, that is _after_ you return
from the handler. If not, try apr_table_set instead of apr_table_setn.

Sorin

Re: Re: How to send a jpeg-file in Handler

Posted by Whut Jia <wh...@163.com>.
Hi Sorin Manolache,
According your ways(ap_send_fd()),it is work.The picture is returned to client.But myself-set cookie content are not returned , why??
Begin sending jpg-file,I set a cookie in headers_out :
r->content_type="image/jpeg";
apr_table_setn(r->headers_out,"Set-Cookie",cookie-contence);
ap_send_fd(fd, request, 0, file_size, &bytes_sent);
return OK;
Besides,the request address of the jpeg picture ishttp://www.whut.com/portal/logout.jpg. This request is sent from the response page of ahttp://www.jjsonicIDP.com/saml/logout.action request .  
Thanks,
ajxs 




At 2011-01-19 21:17:54,"Sorin Manolache" <so...@gmail.com> wrote:

>2011/1/19 Whut  Jia <wh...@163.com>:
>> Can I don't use sub-request??
>> I want only a single picture to client;Just like the same as sending a text :
>> r->content_type="text/html";
>> ap_rputs("helloworld",r);
>> return OK;
>> Please help me !
>> Thanks,
>> ajxs
>>
>
>Try
>
>apr_file_t *fd;
>apr_file_open(&fd, "filename", APR_READ, 0, request->pool);
>apr_off_t file_size = 0;
>apr_file_seek(fd, APR_END, &file_size);
>apr_size_t bytes_sent;
>ap_send_fd(fd, request, 0, file_size, &bytes_sent);
>apr_file_close(fd);
>
>
>S

Re: Re: How to send a jpeg-file in Handler

Posted by Sorin Manolache <so...@gmail.com>.
2011/1/19 Whut  Jia <wh...@163.com>:
> Can I don't use sub-request??
> I want only a single picture to client;Just like the same as sending a text :
> r->content_type="text/html";
> ap_rputs("helloworld",r);
> return OK;
> Please help me !
> Thanks,
> ajxs
>

Try

apr_file_t *fd;
apr_file_open(&fd, "filename", APR_READ, 0, request->pool);
apr_off_t file_size = 0;
apr_file_seek(fd, APR_END, &file_size);
apr_size_t bytes_sent;
ap_send_fd(fd, request, 0, file_size, &bytes_sent);
apr_file_close(fd);


S

Re: Re: How to send a jpeg-file in Handler

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
2011/1/19 Whut  Jia <wh...@163.com>:
> Can I don't use sub-request??
> I want only a single picture to client;Just like the same as sending a text :
> r->content_type="text/html";
> ap_rputs("helloworld",r);
> return OK;

Not sure what you mean. If it's a single static image, convert it to a
C byte array and send it with ap_rwrite().

Re:Re: How to send a jpeg-file in Handler

Posted by Whut Jia <wh...@163.com>.
Can I don't use sub-request??
I want only a single picture to client;Just like the same as sending a text :
r->content_type="text/html";
ap_rputs("helloworld",r);
return OK;
Please help me !
Thanks,
ajxs



At 2011-01-19 20:22:52,"Ben Noordhuis" <in...@bnoordhuis.nl> wrote:

>2011/1/19 Whut  Jia <wh...@163.com>:
>> I want to return a local jpeg-file to client when client request url is /image/metto .In handler module ,I should how to write??
>
>ap_sub_req_lookup_uri() or ap_sub_req_lookup_file()?

Re: How to send a jpeg-file in Handler

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
2011/1/19 Whut  Jia <wh...@163.com>:
> I want to return a local jpeg-file to client when client request url is /image/metto .In handler module ,I should how to write??

ap_sub_req_lookup_uri() or ap_sub_req_lookup_file()?