You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Angelo Immediata <An...@libero.it> on 2006/06/13 17:08:00 UTC

From WrapperResponse to HttpResponse

Hi all.
I'm using cocoon 2.1.7. I'm using the portal block. I have some links where the user must download some files. I want to set the output stream in the response; in order to do this i have used this code in my flow script:

var respo = cocoon.response;
respo.setContentType("application/download");
respo.setHeader("Content-Disposition", "attachment; filename=\"" + nomeFile + "\"");

var resolver = cocoon.getComponent(SourceResolver.ROLE);
var os = respo.getOutputStream();       
var location = percorso+nomeFile;
var source = null;
try {
 source = resolver.resolveURI(location);
}finally {
 if (source != null) {
   resolver.release(source);
 }
}
var iss = source.getInputStream() ;
// copia iss nell os
var bytesRead = -1;
while ((bytesRead = iss.read()) != -1) {
 os.write(bytesRead);
}
os.flush();
os.close();

Now i have an error; the error is that setContentType is not a method; i have seen that cocoon.response gives to me not the HttpResponse but the WrapperResponse...i'ld like to have the HttpResponse from the WrapperReponse...how can i do this? As alternative i'ld like to do that when the user clicks on the link he/she can download the file directly....how can i solve this thing? 

Thanks to all...Angelo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: From WrapperResponse to HttpResponse

Posted by christian bindeballe <ot...@gmail.com>.
hi angelo,

For getting files to users without having the framework "interfere" with
them in any way, try a reader.

As described here:

http://cocoon.apache.org/2.1/userdocs/readers.html

<map:match pattern="somefile">
 <map:read src="path/to/file"/>
</map:match>

there are other readers than just source-readers, for passing images,
for example..

HTH,

christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org