This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to download a file without save/open dialogue box ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to download a file without save/open dialogue box ?" Watch "How to download a file without save/open dialogue box ?" New topic
Author

How to download a file without save/open dialogue box ?

lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
Hi everybody,
i am using below code to only download PDF and DOC file to loacal system but problem is it is showing save/open dialogue box which is not meeting my requirment..can any body please tell me how can i download a file without that dialogue box..?

response.setContentType("application/octet-stream");
response.setHeader( "Content-Disposition", "attachment; filename=\"" + fileName() + "\"" );


Thanks and Regards,
Lokesh Kumar Pattajoshi
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
That's a browser setting. If it's set to show the dialog box, then there's nothing the web app can do about it.
lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
Thanks Burnham for your kind reply is there any way to force browser to only download file without showing dialogue box ?

Please reply.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No. And if there was, I'd get really, really angry that you were bypassing my browser preferences and not allowing me to choose where to download it instead of defaulting to the browser's configured download directory.

Why would you want to have this capability? I can't think of any non-suspicious reason.
lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
Actually we have two buttons called View and Downloads of some documents if user is clicking on View than it should(only pdf docs)open in web browser and if user is clicking Download than it should be downloaded..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That doesn't answer the question, though. And it *can* be downloaded--but wanting to bypass the preferences *I* have set is an invasion of my computer.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

To be even more blunt than David: Do you know what they call code that is downloaded and executed surreptitiously?

Viruses.


Customer surveys are for companies who didn't pay proper attention to begin with.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Presumably you're trying to make your users happy. What you need to do is educate them that this is a browser setting - then they can configure their browsers to either show the dialog, or save the file automatically. That way they have a choice, and you don't need to program anything - now that's a win-win situation!

Tim Holloway wrote:Do you know what they call code that is downloaded and executed surreptitiously?

I don't see any reference to code being downloaded and executed ...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

These days, if you download a PDF ... http://www.computerworld.com/s/article/9184700/Newest_Adobe_zero_day_PDF_exploit_scary_says_researcher

In theory, you can download data without worrying about it being executed as code. In reality, that's not a safe bet.

Not that clandestine downloads of data are innocuous either. The old Unix "lpt" daemon was a security issue because hostile users could do a denial-of-service by jamming in large print jobs. Consider what your response would be if I set up my server to offer up files that were 3TB in size and didn't notifiy you.
Basu Ramanan
Greenhorn

Joined: Sep 14, 2010
Posts: 2
response.setHeader( "Content-Disposition", "attachment; filename=\"" + fileName() + "\"" );

In your above snippet, try setting "Content-Disposition" as "inline" instead of "attachment"

and do this only when you want to "View" and for "download" retain your existing code.

not sure if it will by pass the browser settings, but worth a try.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It won't, but it's also not the same as downloading it--that would view it in the browser.
Basu Ramanan
Greenhorn

Joined: Sep 14, 2010
Posts: 2
David

lokesh pattajoshi wrote:Actually we have two buttons called View and Downloads of some documents if user is clicking on View than it should(only pdf docs)open in web browser and if user is clicking Download than it should be downloaded..


I think thats what Lokesh needs, by download without save/open dialog he means, view the content in web browser.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

lokesh pattajoshi wrote:how can i download a file without that dialogue box..?
and later
lokesh pattajoshi wrote:Actually we have two buttons called View and Downloads of some documents if user is clicking on View than it should(only pdf docs)open in web browser and if user is clicking Download than it should be downloaded..

So I'm pretty sure we're addressing the question as it was originally asked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to download a file without save/open dialogue box ?
 
Similar Threads
How can I bypass the download dialogue box while downloading a file.
how to keep the filename when client opens a streamed file in browser?
how to keep the filename when client opens a streamed file in browser?
problem with file download dialogue box
listening to windows dialogue events in javascript