Solved

Force Google Chrome to Open 'Save As' Dialog Immediately

Posted on 2014-02-21
5
2,704 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
5 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
what about opening a popup with a cool message which after second will redirect to the file?
0
 
LVL 32

Assisted Solution

by:shalomc
shalomc earned 250 total points
Comment Utility
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 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 250 total points
Comment Utility
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 32

Expert Comment

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

Author Closing Comment

by:WalterRR
Comment Utility
Many thanks for the help guys........
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now