Below is the code i’ve written i’ve to download a file,
Now I need to download the file to particular location in client system.I’ll get the path through input from the user.
I know it’s not good to mess client system but I had to do that
//setting the content type of response
response.setContentType("application/"+strFileType);
response.setHeader("content-disposition","attachment; filename="+strFileName+"."+strFileType);
//creating a file input stream object
InputStream input = blob.getBinaryStream();
//declaring a variable
int i;
while((i=input.read())!=-1)
{
//writing output
printWriter.write(i);
}
//closing the streams
input.close();
printWriter.close();
Well the good news (from the user’s perspective!) is that you can’t do it. Even if you “have to”. A web browser is built specifically to stop you (the server side) from doing that kind of thing.
The only away around this is to implement the functionality in a TRUSTED browser plugin or applet or something that the user has to specifically install on his / her machine.
The problem is that the browser has NO WAY to judge whether you are doing this for legitimate purposes … or as an attempt to clobber system / user files, plant malware or any number of other things that may be harmful to the user.
It ain’t going to take the risk of letting you do it, and that is a GOOD THING.