This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

automatic download

 
Suka Hati
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Suka Hati
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic