0

I'm currently working on a document management system that gets a BLOB from a database and displays the document (usually a pdf, but this shouldn't matter). My code works to open the document, but when saving the file after opening, it saves as the URL.pdf. So if the URL of the page to get the file is:

get.jsp?doc=1

then the document is loaded from the database, displayed to the user just fine.

However, if you try to save the file, the default name comes up as

get.pdf

I'd like it to be the actual document name, which is stored in the database. I figure I have to change the URL to do so, but I'm okay with it working a different way, as long as the document can retain the name, which the user probably won't know. I'm using JSP. Thanks in advance.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215

1 Answers1

0

You can do it in your action with the response object. Just replace the "NAME_THE_FILE_HERE" with whatever you want the file to be named.

        httpServletResponse.setContentType( "application/pdf" );
        httpServletResponse.setHeader( "Content-Disposition" , "attachment; filename=" + "NAME_THE_FILE_HERE");
Jonathan Payne
  • 2,223
  • 13
  • 11
  • That works as an attachment, but I want to use it for inline. Attachment forces the download dialog. I'd like the user to view the file and then have the option to save it using Adobe's plugin. – Renegade91127 Apr 09 '12 at 20:11
  • Maybe i'm misunderstanding what you're asking for.. Just change "attachment" to "inline", you can leave the "; filename=" parameter.. httpServletResponse.setHeader( "Content-Disposition" , "inline; filename=" + "NAME_THE_FILE_HERE"); – Jonathan Payne Apr 09 '12 at 20:19
  • That is how I have it set up. The issue comes up because Adobe doens't seem to recognize the filename when used as inline. When you save the PDF using adobe, it saves it with the URL name.pdf. I want it to open, but I want Adobe to save it given its original name. I think, in order to do this, I need to change the URL to a dummy, one that doesn't really exist, but one Adobe will read and get the correct file. – Renegade91127 Apr 09 '12 at 20:23
  • There should be a more eloquent way than that... Here's an example for spoofing the URL: http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page – Jonathan Payne Apr 09 '12 at 20:25
  • This question was asked before as well: http://stackoverflow.com/questions/151079/name-web-pdf-for-better-default-save-filename-in-acrobat – Jonathan Payne Apr 09 '12 at 20:28