wood burning stoves 2.0*
The moose likes Servlets and the fly likes automatic download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "automatic download" Watch "automatic download" New topic
Author

automatic download

Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
hi there....
a have a servlet where it will download a wav for user. a pop-up windows will appear and user can choose whether they want it to open or save.the coding :

public void download(HttpServletRequest req, HttpServletResponse resp)throws IOException {

PrintWriter out=resp.getWriter();

String filePath;

String fileNameNew="temp.wav";
filePath="/bin/"+fileNameNew;
resp.setContentType("audio/x-wav");

resp.addHeader("Content-Disposition", "attachment; filename="+fileNameNew);
try{
File uFile= new File("temp.wav");
int fSize=(int)uFile.length();
FileInputStream fis = new FileInputStream(uFile);
PrintWriter pw = resp.getWriter();
int c=-1;

while ((c = fis.read()) != -1){
pw.print((char)c);
}
// Close output and input resources.
fis.close();
pw.flush();
pw=null;
//response.sendRedirect("borangtest.jsp");
}catch(Exception e){
}
}

despite pop-up windows, is there any way to do so that there will be no pop-up window but it will automaticly open the wav file using user's audio player.

the idea is i dont want to give privillage for user to save that file. they can only open it.

plz help me
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

When you specify "attachment", your telling the browser to open treat the file as an attachment which will always trigger the prompt to run or save.


Change "attachment" to "inline".
As long as your browser has an application registered for the contentType that you've set, it should just open it and run it.

Also, there is no way to prevent your users from saving the file.
If you send it to them, they can find a way to save it.
[ June 22, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sharad Agarwal
Ranch Hand

Joined: Sep 11, 2002
Posts: 167
Originally posted by Ben Souther:

Also, there is no way to prevent your users from saving the file.
If you send it to them, they can find a way to save it.


While I agree with the main point here, I should think that the author can make it mighty difficult for the client to do so. What if we use an applet to run the media file and we enable some kind of cryptography for that one instance. The applet manages the streaming. Needless to say, the stream, eventually reaches the desktop and, in theory, can be grabbed by a determined enough user.

What are the common solutions used in the web-world to make this difficult?


Alco-Haul: We move spirits.
Demented Deliberations of a Dilettante
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
i've tried to change it to inline as u said...but it still prompt the pop-up windows. is there any other way to solve this problem
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If the user doesn't have an application registered to handle the content type that you've specified (resp.setContentType("audio/x-wav") ;) , then no.
That's how browsers behave. If a file with an unknown content type shows up, it asks the user what to do with it.
[ June 22, 2005: Message edited by: Ben Souther ]
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
what i means from my previous reply is that even when i change attachment to inline, user still can save the file. what i want to do is it will not prompt the pop-up menu but it open it automatically for user. am i able to do that? if not, is there any other way or can i dumb the save button which mean that it just a button but if user click on it, nothing happen. or can i take out the save button
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I understand the question. My answer is the same. If you return something with a content type that the browser doesn't understand, it will prompt the user to either save the file or to select an application to open it with.

No, there is no way to alter that prompt screen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: automatic download
 
Similar Threads
How to download csv file
IllegalStateException
download files from UNC using jsp
download help
download pop-up windows error