• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
lokesh pattajoshi
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be even more blunt than David: Do you know what they call code that is downloaded and executed surreptitiously?

Viruses.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't, but it's also not the same as downloading it--that would view it in the browser.
 
Basu Ramanan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic