Can you force a file to be downloaded as an attachment

54 views
Skip to first unread message

Andrew Mackenzie

unread,
Mar 29, 2012, 1:22:05 PM3/29/12
to vosao-cms-...@googlegroups.com
Is there any way to get Vosao to set the HTTP header:

Content-Disposition attachment

for a downloaded file? (e.g. a vCard with mime-type text/x-vcard)

Otherwise for some types of files the mobile browser (android, upto and including 4.0) insists in displaying it inline and you can't have the file opened by any app on the device configured to view it (such as a contacts application).

thanks

Andrew Mackenzie

unread,
May 24, 2012, 9:04:33 AM5/24/12
to vosao-cms-...@googlegroups.com
Any comments on the original question?

We still have the same need, and no idea how to do it in Vosao -> Want to be able to force a file (let's say a PNG image) to be downloaded as an attachment, and avoid it being opened for viewing in the browser.

I would like a workaround now if possible, but in the spirit of being constructive I would suggest a feature request like this:

When you upload a new file to the resources area, have one or more additional fields:
 - checkbox - "Force this file to be downloaded as an attachment" -> this would set Content-Disposition header when file is requested
 - filename text field - "Enter the name for the file to be downloaded" -> this goes into the Content-Disposition header and what the download will be called.
            if left blank, then use uploaded file name?
- mime-type text box - allow the user to enter a MIME type that overrides the default one calculated from the file extension

If the developers and others like that suggestion I can enter as a feature request, no?

Andrew Mackenzie

unread,
Jun 22, 2012, 8:44:22 AM6/22/12
to vosao-cms-...@googlegroups.com
I have done this in two ways:

1) Write a servlet that is responsible for generating the file-download response, and have it set the header in the response.
    Any page can then include an anchor to the file to be downloaded, that will in fact point to this file-download servlet.

2) Similar, but instead of a servlet, have another Vosao page that will generate the file-download response contents.
    In that page, via velocity, set the header:   $response.setHeader( "Content-disposition", "attachment; filename=test.html" )

Emanuele Ziglioli

unread,
Jul 5, 2012, 5:39:26 PM7/5/12
to vosao-cms-...@googlegroups.com
Hi,

you could try with a filter instead of a servlet.
Anyway, a custom servlet could be useful for sourcing files from other places such as the Blob or the Cloud Store
Reply all
Reply to author
Forward
0 new messages