Jahia in English > How to create a...

0 (0 Good)
0 (0 Bad)

How to create a form button to download a file as an attachment ?

by  thbaymet »  2015/08/18 16:50

Hi, 

I created a jahia action which downloads a file as an inputStream - attachment with given filePath. I would like to create a button inside of a form. By clicking to this button a file will be downloaded directly as an attachment - without any preview. 

The first approach was : When a button created, I create a form and when the user clicked on the button I submit the form. However, as the nested forms are not allowed, I can't create this button inside of a form. 

Then I thought to create a form in javascript code and then submit it but I don't know how to handle request response which is an inputstream. 

Can someone help me to find a correct way to resolve this problem ? Is there any way to call a jahia action directly from a button ? And be able to handle inputstream response ? 

Thanks much. 

Regards. 

  • How to create a form button to download a file as an attachment ?
    2015/08/18 16:50

    thbaymet <p>Hi,&nbsp;</p> <p>I created a jahia action which downloads a file as an inputStream - attachment with&nbsp;given filePath. I would like to create a button inside of a form. By clicking to this button a file will be downloaded directly as an attachment - without any preview.&nbsp;</p> <p>The first approach was : When a button created, I create a form and when the user clicked on the button I submit the form. However, as the nested forms are not allowed, I can&#39;t create this button inside of a form.&nbsp;</p> <p>Then I thought to create a form in javascript code and then submit it but I don&#39;t know how to handle request response which is an inputstream.&nbsp;</p> <p>Can someone help me to find a correct way&nbsp;to resolve&nbsp;this problem ? Is there any way to call a jahia action directly from a button ? And be able to handle inputstream response ?&nbsp;</p> <p>Thanks much.&nbsp;</p> <p>Regards.&nbsp;</p>

  • Number of messages  19
    Registration date Aug 18, 2015
    0 (0 Good)
    0 (0 Bad)

    Re : How to create a form button to download a file as an attachment ?

    by  thbaymet »  2015/08/19 12:13

    I created my "little" form with JS and once the page loaded I appended it to the body. But I would like to have a "good" solution to this. Thanks.

  • Re : How to create a form button to download a file as an attachment ?
    2015/08/19 12:13

    thbaymet <p>I created my &quot;little&quot; form with JS and once the page loaded I appended it to the body. But I would like to have a &quot;good&quot; solution to this. Thanks.</p>

  • Number of messages  19
    Registration date Aug 19, 2015
    1 (1 Good)
    0 (0 Bad)

    Re: How to create a form button to download a file as an attachment ?

    by  cedmail »  2015/08/19 14:04

    You could just create a link to the file using it's path and your action. Something like currentFile.getPath().download.do. In you action you should set the Header Content-Disposition to attachment, and on the link use a target="_blank" which will download the file with Save As dialog. Action can be called with a get method. You can also use an iframe to hide the download and have no tab/window opened by the browser.
    http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery

     

     

     

     

    misterCedricMailleux

    Cedric Mailleux (cedmail)

    Number of messages  11
    Registration date
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page