'render' an octet stream

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

'render' an octet stream

Edward Povazan
Hello,

I have a controller that creates a zip file based on the url arguments. How do I
return the zip to the client? I have a byte[] containing the zip bytes. So
render(contentType:"application/octet-stream", ??)
I started with text which was trivial to work with, but now that I have a zip,
what do I do with it :)

Thanks
-Ed

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: 'render' an octet stream

graemer
Hmm there is no way to do that with the render method at the moment,
please raise an issue as it would be a good feature to add. You can
however do it with standard servlet calls:

def createZip = {
     byte[] zip = .. // create somehow

     response.contentType = "application/octet-stream"
     response.outputStream << zip
}

Still pretty concise, might be worth documentation how to do this on
the wiki when you manage it :-)

Graeme

On 6/27/06, Edward Povazan <[hidden email]> wrote:

> Hello,
>
> I have a controller that creates a zip file based on the url arguments. How do I
> return the zip to the client? I have a byte[] containing the zip bytes. So
> render(contentType:"application/octet-stream", ??)
> I started with text which was trivial to work with, but now that I have a zip,
> what do I do with it :)
>
> Thanks
> -Ed
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: 'render' an octet stream

Marc Palmer Local

On 27 Jun 2006, at 09:19, Graeme Rocher wrote:

> Hmm there is no way to do that with the render method at the moment,
> please raise an issue as it would be a good feature to add. You can
> however do it with standard servlet calls:
>
> def createZip = {
>     byte[] zip = .. // create somehow
>
>     response.contentType = "application/octet-stream"
>     response.outputStream << zip
> }
>
> Still pretty concise, might be worth documentation how to do this on
> the wiki when you manage it :-)

Typically, depending on what you want to happen with the file (i.e.  
save to disk vs. display in browser) you will also want to set other  
response headers such as Content-Disposition if I recall correctly.

I would consider using a view to do this... assuming GSP pages don't  
produce whitespace or other content at the start and allow you to  
immediately set headers. I don't know the answer to that at the moment.

It's a toss-up though - but strictly speaking it is a view issue, but  
your GSP might need to play with the output stream directly as the  
above example does. Not pretty, and would this work with GSP or would  
it screw up rendering?

Marc
~ ~ ~
Marc Palmer ([hidden email])
Consultant/Analyst
AnyWare Ltd.
http://www.anyware.co.uk/


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: 'render' an octet stream

Edward Povazan
In reply to this post by graemer
Thanks Graeme, works perfectly. Grails rocks! (I am sure you hear that repeatedly)

I added an entry to the FAQ to a new 'Controller' section at the bottom:
http://docs.codehaus.org/display/GRAILS/FAQ
A new feature request issue is at http://jira.codehaus.org/browse/GRAILS-187,
hmm, perhaps it should be under 'improvement'?

-Ed

Graeme Rocher wrote:

> Hmm there is no way to do that with the render method at the moment,
> please raise an issue as it would be a good feature to add. You can
> however do it with standard servlet calls:
>
> def createZip = {
>     byte[] zip = .. // create somehow
>
>     response.contentType = "application/octet-stream"
>     response.outputStream << zip
> }
>
> Still pretty concise, might be worth documentation how to do this on
> the wiki when you manage it :-)
>
> Graeme
>
> On 6/27/06, Edward Povazan <[hidden email]> wrote:
>> Hello,
>>
>> I have a controller that creates a zip file based on the url
>> arguments. How do I
>> return the zip to the client? I have a byte[] containing the zip
>> bytes. So
>> render(contentType:"application/octet-stream", ??)
>> I started with text which was trivial to work with, but now that I
>> have a zip,
>> what do I do with it :)
>>
>> Thanks
>> -Ed
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email