Content Disposition

I am working on an application that allows the user to view various file types inline in the browser. I have encountered a problem when the client does not have the relevant application for a file type e.g. tif.
IE recognises this and offers the user the option to save the file. The file is rendered in an iframe and retrieved from the database via the BSP controller. Thus when offered to save the file the user is prompted with the name of the controller, not the name of the file.
Using a disposition of inline with a filename was tried, but in response to this IE always opens the file externally.
I took a look at RFC 1806 with respect to this and thought it would be possible to use the filename with inline disposition:
<i>The presence of the filename parameter does not force an implementation to write the entity to a separate file. It is perfectly acceptable for implementations to leave the entity as part of the normal mail stream unless the user requests otherwise. As a consequence, the parameter may be used on any MIME entity, even `inline' ones. These will not normally be written to files, but the parameter could be used to provide a filename if the receiving user should choose to write the part to a file.</i>
An alternative I am looking at is writing the file into the ICM cache and having the controller send a redirect for IE to access the file.
Before I make the changes I am curious if anyone else has another solution for this.

To clarify about storing the file in the ICM cache I will be using the approach identified in weblog /people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents and setting the display url for the cache upload and not directly performing a redirect.
Regards
JohnA

Similar Messages

  • Specifying pdf document's name in browser - content-disposition problem

    Hello ,
    I want to open a PDF document in browser, which needs to have a specified filename when user tries to save it.
    My web app sends an "application/pdf" document back to the browser.
    I use the Content-Disposition HTTP header to instruct the browser to open the document inline, i.e. using the appropriate plugin, which is Adobe PDF in this case. When the user clicks Save As..., the document filename needs to be the one specified by the same HTTP header. Here is the code:
    response.setContentType("application/pdf");
    String contentDisposition = "inline; filename=\"filename.pdf\"";
    response.setHeader ("Content-Disposition", contentDisposition);
    response.setHeader ("Content-Length",new Long(file.length()).toString());Unfortunately this does not work for me. Document opens fine, but I can't get it to have the name I specified. The plugin uses the default name, which is the full URL of the document. I tried several combinations of HTTP headers, but neither worked. I tried putting an additional GET request parameter at the end of the URL, like ...&filename=filename.pdf , but that didn't work either.
    I tried Adobe 7.0 and 8.1.2.
    Any suggestions ?
    Thanks a lot!

    Thank you very much for your answer.
    Needless to say I tried opening the document in IE, FF and Chrome, and neither worked.
    I had a look at the code at your web site, and saw that you were serving files for direct download: Content-Dispositoin:attachment... .
    This works fine for me too, and the filename is recognized correctly in that case. The problem is, I want to display the PDF inline...
    My server is not configured for URL rewriting, and I would be probably quite some problem to make this app work with it, so the /filename.pdf is not an option for me.
    Edited by: matavulj on Sep 25, 2008 7:21 AM

  • How to specify the charatcer encoding for the parametes Content-Disposition

    I want to download a file with chinese name .
    response.setHeader("Content-Disposition","attachment; filename=" + fileName);
    the above part of code is working fine for english file names. but i am facing problem when i try to get file with chinese name .
    The pop up window is not defaulting with the chinese name .
    When i searched for net , in one rfc it was specified how to do that one.
    http://www.faqs.org/rfcs/rfc2184.html.
    I tried it but .. could not able to solve the problem.

    Hi,
    Am facing similar problem with russian and japanese characters in file name.
    I tried the UrlEncoder.encode(filename, "utf-8') api to encode the file name. This worked fine with IE but firefox and safari shows junk for japanese/russian characters.
    Anyone having an idea abt this?
    Thanks,
    Kapil

  • Setting the title for File download dialog when using content-disposition

    I am trying to send a file from server to client (browser). I am setting the content type of the resopnse and using the "content-disposition" header and giving the filename.
    But the issue is, when it is downloading and the dialog box is showing the progress bar, The title of the dialog box is showing something like "40% of localhost:9080.....". It doesn't show the file name in the title bar. Also, if the URL is very long (I am passing some get parameters and the servlet name is also long), I get junk characters like small boxes.
    How to set this title in the servlet?

    Is there a reason why you have to use FileReference.Save versus File.browseForSave?  In Adobe AIR, the File class, which extends the FileReference class,    provides more capabilities and has less security restrictions than the FileReference class.  Using File.browseForSave, it has a title:String parameter which is a string that is diplayed in the title bar of the dialog box.

  • Content-Disposition in IE

    Hi
    I want to stream a pdf file and then show in the browser . res.setHeader("Content-Disposition", "inline;filename=temp.pdf;");
    This works with netscape but in IE it shows blank page after starting a Acrobat process.
    But if i use
    res.setHeader("Content-Disposition", "attachment;filename=temp.pdf;"); this works with IE and netscape both . I am not able to figureout what is the problem . Anyone knows solution for this problem ? Please let me know .
    Thanks in advance
    Amit Kumar

    Hi
    I want to stream a pdf file and then show in the
    he browser . res.setHeader("Content-Disposition",
    "inline;filename=temp.pdf;");
    Hi,
    I am currently working with reports being exported to excel
    You can try this :
    res.setContentType("application/pdf");
    I think it should work ....but I am not sure whether the mime type for pdf is ("application/pdf"); or ("application/vnd-pdf");
    try both ....let me noe if fit works ....:)
    cheers

  • Problem with non-ASCII file name in content disposition header

    Hi All,
    I am facing some problems with the non-ASCII file name incase of content-disposition header. I read from the RFC 2183 that if the file name contains non-ASCII characters then the same should be encoded before sending to browser. I did the same but realized 2 problems:
    1. The name of the file is truncated in case the file name is slightly long for e.g. �����������j�b�g��������������������������.txt
    2. Also when the same file is opened in notepad, the title is showing encoded name %E6%9C%80%E4%B8%8A%E4%BD%8D.....
    Overall, I feel that the browser is not understanding or responding to the encoded header values.
    Is there any solution to this problem? I am using Microsoft IE 6.0.
    The code snippet is given below:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              String fileName = "�����������j�b�g��������������������������.txt";          
              fileName = URLEncoder.encode(fileName, "UTF-8");
              resp.setCharacterEncoding("UTF-8");
              resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
              resp.setContentType("application/download-binary");
              String s = "This is inside txt file";
              resp.getOutputStream().write(s.getBytes("UTF-8"));
              return;
         }Any help or pointer would be highly appreciated.
    Thanks and Regards,
    Ashish

    The MIME standards for non-ASCII filenames are not widely implemented.
    Many mailers use an ad hoc method for encoding filenames. JavaMail
    supports both methods, but you need to set properties, such as the
    mail.mime.encodefilename property. See the JavaMail javadocs for
    the javax.mail.internet package.

  • Inline type of Content-Disposition problem in IE

    Hi,
    In a project, we need post some information from applet to servlet. The servlet will send some files back. We like the files shown on browsers. So we set the header in servlet as
    response.setHeader("Content-Disposition",
    "inline;filename=\"" + fileName + "\"");
    We use JSobject in applet to call form from a html file to post the information to servlet, target of the form is set as "_blank", which suppose will open a new browser and show the file. For example if the file is a word file, the IE will show the file inside browser.
    However, if two files need to be shown, only the first file is shown, the other browser is blank, and when you kill the blank window, the other will turn to blank window too. We test other types of file, xls files have similar problem, the PDF files work OK. Two things can fix the problem, one is set the form method to ��get��, the other is changing the header from ��inline�� to ��attachment��. But we can't use any of them under the project requirement. Has anyone experienced such wield behavior and know the reason? Is this the bug of IE?
    Thanks in advance!

    Here are a little more about the file types.
    The files we test have problems are msword or excel files, I think all MS office type files have the problem. Same problem even you mix them, for example one word file and one excel give you the same problem as two word files.
    However there is no problem if I view several PDF files. If we mix the word file with pdf file. If the first file to view is PDF, then it works OK. Otherwise same problem.
    The browser we are testing IE 6.0 with SP1.

  • Bug: DocumentManager does not emit Content-Disposition header

    Good afternoon,
    I have a process with an output variable of type Document: this document has a defined filename. When invoking the process, instead of downloading the file with the defined filename, I was receiving a file with a name that looks like an MD5 hash.
    The fault for this lies with the DocumentManager application: it does not emit the content disposition header that would suggest to the browser what the real name of the octet-stream is. As such, without this header, the user agent will assume that the file-name is the endpoint name.
    The trace of the HTTP exchange is below:
    GET http://HOST:8080/rest/services/APP/SERVICE:1.0?q=83
    Cache-Control     no-cache, must-revalidate
    Date              Wed, 17 Nov 2010 12:54:29 GMT
    Pragma            no-cache
    Transfer-Encoding chunked
    Location          http://HOST:8080/DocumentManager/docm$(NUMBER)/$(HASH)?type=$(TYPE)
    X-Powered-By      Servlet/2.5 JSP/2.1
    GET http://HOST:8080/DocumentManager/docm$(NUMBER)/$(HASH)?type=$(TYPE)
    Date              Wed, 17 Nov 2010 12:54:35 GMT
    Transfer-Encoding chunked
    Content-Type      application/vnd.ms-excel
    X-Powered-By      Servlet/2.5 JSP/2.1
    The 2nd HTTP request should have included the specified header, like so:
    Content-Disposition: attachment; filename=MyExcel.xls
    RFC 2183: The Content-Disposition Header Field
    Best regards,

    Hi Robert,
    thanks for the reply. This is certainly a different aspect of the problem. The HTTP response that serves the dynamic portion (the one with the timestamp) has the response headers:
    HTTP/1.1 200 OK
    Date: Wed, 21 Jan 2015 18:05:53 GMT
    Server: Apache/2.2.29 (Unix)
    X-Powered-By: PHP/5.3.29
    Cache-Control: max-age=100000, public
    Keep-Alive: timeout=3, max=95
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: application/xml
    So it is marked as cacheable. 
    My expectation now is this:
    - when clicking the "refresh" link in the markup, there should be no new timestamp. Reason is that the dynamic part should have been cached and I would expect the XSLT engine to use the browser's caching layer when fetching fragments
    - when hitting "F5" I would expect a revalidation request to be send to the server (e.g. max-age=0 or if-modified-since). Then the server can revalidate the fragment. In my example case the fragment would be served in any case, so I would expect a
    new timestamp
    - when hitting "CTRL+F5" I would expect a request with "cache-control: no-cache" that enforces the server side caches to always return new content. I would expect a new timestamp in this case.
    What I observe is that:
    - Chrome and FF work as expected
    - IE (10/11) will always fetch the dynamic fragment, so I will even see a new timestamp when clicking the refresh link. Also the "if-none-match" header in the "F5" case is NOT forwarded to the dynamic fragment (potentially because it is
    not cached in the browser at all)
    Carsten

  • Upload file - get rid of Content-Disposition: form-data;

    Hello,there.I just want to know if somebody had succesfully solved problem of getting rid of rows
    at uploaded file
    -----------------------------7d23c05be8
    Content-Disposition: form-data; name="fromflr"; filename="C:\WINDOWS\Desktop\Clock"
    Content-Type: text/plain
    "Some Data"
    -----------------------------7d23c05be8
    Content-Disposition: form-data; name="toflr"
    HARGAL
    I just need get rid of rows like
    -----------------------------7d23c05be8
    Content-Disposition: form-data; name="toflr"
    HARGAL
    and leave only "Some Data" in uploaded file.
    Any suggestion would be appreciate.

    See for example Upload taglib from Coldtags suite:
    http://www.servletsuite.com/jsp.htm

  • Content-Disposition Convert to RTF

    Hi I have some problem with my jsp.
    Apprarently I am able to populate my page into MS-WORDS as RTF
    However I encounter Garbage value like
    &Amp; instead of &
    May there be some better way to convert? May it due to some settings i need to set on the response.XXX???
    Thanks for your help. Deeply appreciated.
    Derek Sum
    <%@ page language="java"%>
    <%@page import="test.kis.dto.*"%>
    <%@page import="test.kis.utility.*"%>
    <%@page import="java.util.*"%>
    <%@ taglib uri="/WEB-INF/struts-bean" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic" prefix="logic" %>
    <%@ taglib uri="/WEB-INF/standard/c.tld" prefix="c" %>
    <%
    response.setHeader ("Content-Disposition", "filename=appln.rtf;");
    response.setContentType("appln.rtf");
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("dd/MMM/yy");
    String today = format.format(new java.util.Date());
    %>

    To export PDF to RTF/Word file
    Using Adobe ReaderX or Reader XI
    Launch Adobe Reader X or Reader XI
    Select “Tools” and click “Sign In” link to sign in with your Adobe ID and password
    Select “Export PDF” then click “Select PDF file” link to choose your PDF file
    Select format from “Convert To” pull down menu(docx, doc,rtf,xlsx)
    Click “Convert”
    Click “Download Converted File” link to download the file to your computer after the process is completed.
    Using Web UI
    Log into https://createpdf.acrobat.com/signin.html with your Adobe ID and password
    Select “Export from PDF”
    Click “Select Files” button then choose your PDF file
    Select the format from the list below
    Check ON “Recognized text in” if your PDF file is scanned images to recognize the image to text
    Click “Export” button
    Click “Download” button in the progress bar after completion of exporting to download the file to your computer.
    Note: All exported files are stored at https//files.acrobat.com
    Hisami

  • Content-Disposition inline/attachment

    I am using Content-Disposition for excel file download as below:
    I have searched the forum but not able to get the exact answer or solution. Please also guide me to some url if possible.
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "inline; filename=xyz.xls" );
    If I am using inline attribute but I am not able to specify the filename as xyz.xls and by default fileName provided by browser is the request URL(action-mapping in case of struts).
    But it works fine with attachment attribute and prompts for the exact file Name and works fine.
    I want to know how to specify the desired fileName with inline Attribute ? I am using the struts based request for Excel file generation.
    Best Regards,
    Amber Gupta

    if You dont't mind , I just want to tell u something on this code.
    If im wrong, Please tell me why? and what is the best way of acheiving it then,
    the code below loads whole filedata and it does not matter how big the file is. Don't you think that it will heat up the memory by doing so. and consider the method what he was doing is perfectly right. but is there any other solution/wrong with above code what MR/ms/Mrs Kenneth has written like.
    I just wanted to know the answer what is the wrong with MR. Kennth Code since i looked at it as a perfect working code(but with some glicth).
    with Regards
    Lokesh T.c
    FileInputStream in = new FileInputStream(fileToDownload);
    ServletOutputStream out = response.getOutputStream();
    int bytesRead = 0;
    byte byteArray[] = new byte[fileTODownload.length()];
    // Read in bytes through file stream, and write out through servlet stream
    /*while( ( bytesRead = in.read( byteArray ) ) != -1 ) {
    out.write( byteArray, 0, bytesRead );
    in.read(bytesArray,0,fileTODownload.length());
    out.write(bytesArray,0,fileTODownload.length());
    in.close();
    out.flush();
    out.close();

  • Content-disposition header - office 2007 warning

    When I set the response header in the following way- using content-disposition inline- and try to open a xls file, I don't get the open/save dialog due to content-disposition but a warning message comes from office 2007 saying "The file you're trying to open is in a different format..."
    response.setHeader{"content-disposition","inline;filename="+filename}Whereas, for the response header set in this way- using content-disposition attachment- the open/save dialog appears without being followed by a warning from office 2007.
    response.setHeader{"content-disposition","attachment;filename="+filename}Is there anyway I can avoid open/save dialog due to content-disposition and still not get the warning from office 2007?
    Edited by: 1normalguy on Nov 18, 2008 10:54 PM

    The problem is that "xls" is a different format. Office 2007 uses xlsx because the format (for all Office documents) has been completely altered in Office 2007. They are no longer even close to being the same thing, anymore.
    Edit: Gods! So many typos in so small a text!

  • Content-Disposition not working!

    Hi!, I've a servlet which its purpose is to read a file and write it later using a ServletOutputStream. This file must not be wrote as text, but instead the idea is to write it and then browser open it with a specific application. The extension of this file is already asssociated with the program that I want to use to open it. In fact, if I use a url link to the file, the browser requests the application and all goes fine, but I want that this application runs inside the browser, so I'm using content-disposition: inline; in order to do this, but I can't make it! The browser always try to download the file. My code is this:
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class imflpruebas extends HttpServlet{
         private ResultSet rs, rs2;
         private Connection connection;
         private Statement statement;
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
              doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
              response.setHeader("Content-Disposition","inline");
              response.setContentType("application");
              String sFileName = "F:\\jakarta-tomcat-4.1.24\\webapps\\ImaxFileWeb\\temp\\reno_PRUEBA_0_0_0.IMX";
              File file = new File(sFileName);      
              byte[] byteContents = new byte[(int)file.length()];                
              FileInputStream in = new FileInputStream(sFileName);                
              int retcd = in.read(byteContents);                
              in.close();
              ServletOutputStream out = response.getOutputStream();
              out.write(byteContents);
              out.flush();
              out.close();
    }          I've tried to put the content type before the set header and the result is the same.
    Any ideas?
    Best whishes
    Raul          

    Hello Raul,
    There are a few things to consider. First of all, how do you want the browser to tell which application to use. Your content-type is very non-specific so the browser would never be able to tell by itself. Using a mime-type which has been mapped to an application might do a lot.
    Second, if you are using IE mime-types have little influence. IE tries to recognize the data by looking at the raw bytes and see if it recognizes the format. If not, IE will look at the URL and determine what to do with the data based on the URl extension. So if you have a link http://..../xxx.xls IE will try to show the data using Excel (if installed obviously). Adding such an extension (that can be ignored by the servlet) can do the trick with IE.
    If using IE check the Windows Explorer file settings (based on extensions). There is an "advanced" property called "confirm open before download" which should be cleared to allow an automatic open. Clearing the check "always ask before downloading" on the browser popup has no effect at all.
    Hope this helps.
    Regards,
    Silvio Bierman

  • Content-Disposition inline Not working

    Hi all,
    I am using Orion application server as Web server. I like to open a file in client side form the server. Which one is known MIME type. I don't want the IE to prompt the user for Save as/ Open from the current location.
    I am using "inline" argument in Content-Disposition header. Eventhough i am getting promt dialog box in client side.
    The following is my code.
    <%@ page import="java.io.*" %>
    <%@ page import="java.net.*" %>
    <% response.setContentType("application/pdf"); %>
    <% response.setHeader("Content-Disposition" , "inline;filename=test.pdf" ); %>
    <%
    String fileURL = "http://java1/examples/jsp/test.pdf";
         ServletOutputStream sout = response.getOutputStream ();
         URL url = new URL ( fileURL );
         BufferedInputStream bis = null;
         BufferedOutputStream bos = null;
         try {
              URLConnection conn = url.openConnection();
              // Use Buffered Stream for reading/writing.
              bis = new BufferedInputStream(conn.getInputStream());
              bos = new BufferedOutputStream(sout);
              byte[] buff = new byte[2048];
              int bytesRead;
              // Simple read/write loop.
              while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                   bos.write(buff, 0, bytesRead);
         catch(Exception ex){
              System.out.println(ex.toString());
    %>
    Any one give the soloution for this problem. I hope there is no problem with the source code. I want to avoid the dialog box while downloading in the client side.
    Thanks
    Prabhu.

    Hi,
    Please let me know in which browser you are trying to do this, since it as some problem with IE5. You can try this, using the Netscape browser which doesn't have any problem.
    Hope this helps.
    Senthil Babu J

  • Content-Disposition - Dynamically set in Mail Adapter

    Hi All,
    I need to dynamically set the Content-Disposition in the receiver mail adapter so as to facilitate dynamic names for my attachment in the mail.
    In case i use messagetransform bean, I will have to hard code the name as part of the parameter value in the adapter.
    Is there any way i can utilize the ASMA and dynamic configuration here?
    The specified item was not found. - i referred the blog but instead of setting the
    attachmentXML.setName(mailFileName);
    attachmentXML.setContentType("text/xml");
    attachmentXML.setContent(by);
    I need to set the content disposition. Is there any way?
    Appreciate all help on this issue.
    Regards,
    Shabz

    Hi Vijay,
    Do have the solution for this? I also have the same requirement.
    Please forward me the solution.
    Thanks,
    Nat

  • PDF content disposition on IE

    Hi,
    I am having difficulties in displaying PDF content from JSP. Obviously URL ends with mypdffile.jsp. From the JSP, I set attributes as follows. It works as intended on Firefox. Not on IE;
    response.setContentType("application/pdf;charset=UTF-8");
    response.setHeader("Content-Disposition", "inline;filename=\"Document.pdf\""); Any suggestions how I can fix this mess?

    On IE, it shows nothing! I can see that it reads something then nothing shows up. It is meant to display inside the viewing frame without creating external frames. If I change to "Content-disposition: attachment; filename=ddd.pdf", it comes out with PDF view frame. If you move the frame, you see lots of dirty traces on Windows frame!
    It may IE is not handling extension well.Or size information may be required.
    JSP is convenient to write changeable reports. PDF is generated using iText.
    Regards.

Maybe you are looking for

  • Upgrade for a G3-350 with Mac OS 8.6

    My son was recently given an old imac from 1999. The only infor I can find for it is that it is a G3-350 and the OS is 8.6. What would I be able to upgrade the OS to? I am a pc user, and this is my first time dealing with a MAC, so I don't know anyth

  • Simple external drive question please

    Hi all, quick and probably rather basic question here.... I have a mac mini which we use as a family internet channel, email and the occasional synching of an Iphone and iPod Touch. I am getting memory almost full messages from my mac mini. It is. Ho

  • Apple Keyboard USB Low Power Issue

    OK. I'm using a Windows machine and my G4 for a project and to save space and complexity I bought a Trendnet TK-207 USB switcher to use one keyboard, my G4's, and one mouse, a Mighty Mouse. Both mouse and keyboard work fine powered by the HP machine

  • Boot Problem with 761GX

    This story is kind of long but I'll paraphrase it as best as possible. So I went out and bought a Vista upgrade the Home Premium one. I had run the compadibility tool before and it told me my video card, which was fairly old, was out of date to run t

  • Triversity Integration Question

    Hello, The company I work for has a certified implementation of the BAS interface.  One of our customers has inquired whether or not our address cleansing works with Triversity.  Can you please tell me if the Triversity integration utilizes the BAS i