On 10 Aug 2009, at 23:32, Damjan wrote:
>
>> This may be a silly question, but how do I return a file as my
>> response?
>>
>> For example, for the purposes of tracking email opens I need to
>> return
>> a transparent gif as my response. Can I just set the body of the
>> response to be the file content, and set the correct mime-type? Or
>> do
>> I need to do something different?
>>
>> Unfortunately I'm working with a legacy system, so I can't not return
>> a transparent gif for the moment, but if there's better ways to do it
>> in the long-term, I'd also be interested.
>
> afaik something like:
>
> fp = open("blank.gif")
> return BaseResponse(wrap_file(environ, fp), mimetype='image/gif',
> direct_passthrough=True)
That's wonderful thank you. It seems to work perfectly.
FYI I implemented it like this:
transparent_gif = StringIO("GIF89a\x01\x00\x01\x00\x80\x00\x00\xff\xff
\xff\x00\x00\x00!
\xf9
\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D
\x01\x00;")
def get_transparent_gif_response(request):
return BaseResponse(wrap_file(request.environ, transparent_gif),
mimetype='image/gif')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---