download a file to particular location in client s

2019-05-25 08:22发布

问题:

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();

回答1:

I know it's not good to mess client system but I had to do that ....

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.


... where to use the path taken from the user and i'm programming this just like ftp but server side is a database

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.



回答2:

This needs an update of file download location of browser,[note: if we update this all files will be download to that path]

refer the below links you may get the idea :

How to change the download folder destenation in firefox?

How to check the location of download folder programmatically in browsers like Safari, Firefox etc on Mac?

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6ff178a2-5131-43d4-b4c0-efb4a2112e95



回答3:

If you are inside an intranet and can trust a server, use an applet or similar technolofgies with granted access privileges... but once again this is REALLY bad.