This content has been marked as final.
Show 8 replies
-
1. Re: Usage for downloading uploaded file
twocoasttb Jul 12, 2007 1:26 AM (in response to goku2)You have to write a servlet to do this. I think the seamspace app provides a good example.
-
2. Re: Usage for downloading uploaded file
tino4 Jul 17, 2007 6:08 AM (in response to goku2)"twocoasttb" wrote:
You have to write a servlet to do this. I think the seamspace app provides a good example.
hi,
could you plz give some more infos ?
i can't find it in seamspace examples
thx -
3. Re: Usage for downloading uploaded file
carloszaniolo Jul 17, 2007 3:09 PM (in response to goku2)Hi,
try this:<s:link value="Donwload #{textm.name}" rendered="#{! empty textm.text}" action="#{textmcontroller.download}" />
public void download() { if (textm.getText() != null) { byte[] file = loadFile(); String name = getName(); String type = getContentType(); MyUtil.download(file, name, type); } }
public static void download(byte[] file, String name, String type) { FacesContext facesContext = (FacesContext) Component.getInstance("facesContext"); if (!facesContext.getResponseComplete()) { HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setContentType(type); response.setContentLength(file.length); response.setHeader("Content-disposition","attachment; filename=" + name); ServletOutputStream out; try { out = response.getOutputStream(); out.write(file); out.flush(); } catch (IOException e) { //TODO: something } facesContext.responseComplete(); } }
-
4. Re: Usage for downloading uploaded file
carloszaniolo Jul 17, 2007 3:18 PM (in response to goku2)But it wold be usefull to have in Seam:
<s:filedownload name="#{name}" contentType="#{type}" file="#{file}" /> -
5. Re: Usage for downloading uploaded file
tino4 Jul 18, 2007 6:16 AM (in response to goku2)Hi carlos,
thx for your responds.
i still don't understand, which one is your textmcontroller java code?
thx in advance -
6. Re: Usage for downloading uploaded file
carloszaniolo Jul 18, 2007 8:25 AM (in response to goku2)Sorry,
public void download()
is from textmcontroller.
The other is my download helper method and is the important one... -
7. Re: Usage for downloading uploaded file
tino4 Jul 18, 2007 10:04 AM (in response to goku2)"carloszaniolo" wrote:
Sorry,public void download()
is from textmcontroller.
The other is my download helper method and is the important one...
thank you sir....it works...
but the downloaded file type is undefined, so that you can't open it.
the file is converted from blob into byte.
the size is correct.
well i think it's just a convert problem..
i'm still working on it and try to fix it.
i let you know -
8. Re: Usage for downloading uploaded file
tino4 Jul 19, 2007 3:39 AM (in response to goku2)"tino4" wrote:
"carloszaniolo" wrote:
Sorry,public void download()
is from textmcontroller.
The other is my download helper method and is the important one...
thank you sir....it works...
but the downloaded file type is undefined, so that you can't open it.
the file is converted from blob into byte.
the size is correct.
well i think it's just a convert problem..
i'm still working on it and try to fix it.
i let you know
Hi Carloszaniolo,
it's working now. now i can open the downloaded uploaded file.
the problem like i said was the convert itself.
well actually you don't need to convert at all :)
thank you sir