Solved

Force Google Chrome to Open 'Save As' Dialog Immediately

Posted on 2014-02-21
5
2,957 Views
Last Modified: 2014-02-24
I have a java servlet that returns a large pdf file to UI/browser for download. It takes the server 10-20 seconds to generate the file so I am trying to pop up the save as dialog ASAP to avoid browser lag, user confusion, wait and so on.

I only want to send headers etc. just to make connection, when server has its work done we flush the rest of payload.

I send <?xml XXXXXXXXXXXXXX?> immediately after headers and flush buffer. this works well in firefox and the browser shows the dialog thus eliminating the browser wait,,, this does not work for chrome.

Any help appreciated.
0
Comment
Question by:WalterRR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39879268
what about opening a popup with a cool message which after second will redirect to the file?
0
 
LVL 33

Assisted Solution

by:shalomc
shalomc earned 250 total points
ID: 39879434
You need to send the Content-Disposition http header, like in this php example.

$path = "path/to/file.pdf";
$filename = "file.pdf";
header('Content-Transfer-Encoding: binary');  
header('Accept-Ranges: bytes');  
header('Content-Length: ' . filesize($path));  
header('Content-Encoding: none');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=' . $filename);  
readfile($path);  

Of course, java being java, it is a bit more complex in your case.
See this reference for an example how to add custome http headers in Java
http://vangjee.wordpress.com/2009/02/25/how-to-modify-request-headers-in-a-j2ee-web-application/
0
 
LVL 43

Accepted Solution

by:
Rob earned 250 total points
ID: 39881172
Shalomc is close but if you specify the following headers the browser will not try to display the file but will prompt the user to download it:

header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
0
 
LVL 33

Expert Comment

by:shalomc
ID: 39881287
I like the "Content-Disposition: attachment " header better, but suit yourself to whichever method works for you.
0
 

Author Closing Comment

by:WalterRR
ID: 39882659
Many thanks for the help guys........
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question