Bookmark Topic Watch Topic
  • New Topic

downloading a file from server

 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,


response.setContentType( "application/vnd.ms-excel" );
response.setHeader("Content-Disposition","attachment; filename=\""+MSG_LVL_NO+"_"+cifId+".xls\"");

response.setHeader("cache-control", "no-cache");
response.setHeader("Pragma","no-cache");
java.net.URL url=new java.net.URL("file://./"+"Download-back/"+MSG_LVL_NO+"_"+cifId+".xls");
File file=new File(url.getPath());
System.out.println("Path:"+file.getPath());
System.out.print("file exist:"+file.exists());
java.io.FileInputStream fileInputStream =new java.io.FileInputStream(file);
BufferedInputStream bin=new BufferedInputStream(fileInputStream);

int i;
byte[] b=new byte[10];
ServletOutputStream sosStream= response.getOutputStream();
while ((i=bin.read())!=-1)
{
sosStream.write(i);;
}

sosStream.flush();
sosStream.close();
bin.close();
fileInputStream.close();

with above code i can able to download a file from server , here download is asking for save as location to the user , instead of that, location to get down load will come from the textfiled form from previous page (user will give where to get download in the textfield), file has get download to user given loaction , instead of opening save as dialog to the user each and every time, it has download to the location entered in the textfield.. how to get this....
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm a little unsure what your asking.
If you're asking if there is a way to force a download to a user's machine without prompting them for a location, no.

To allow this would be a security nightmare.
If you use "inline" instead of "attachment" in your Content-Disposition header, the browser will save it to the user's Temporary Internet Files folder and open it with the registered applictation but only if there is a registered app for the specified content type. Otherwise, it will open the 'save as' dialog.
 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hai!


i have tried inline instead of attchments long back it is getting opening the file in browser, wat i want user will enter the location where to get download in textfiled i.e location to download file in his machine....

it has to download in that location instead of asking 'Save as' Dialog box each and every time...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Browsers expressly forbid this for a good reason.

The user will have to approve and select a location for each download every time. This is a basic security feature.
If this capability is really important to you. You might want to look into a signed applet.
 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
here requirements is like that colud u pls tell me exact solution to get download
 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
here it is getting downloading only one file rather than all files, for reaming files are NOT loading and it is not showning Save as dialog bo, it is asking one time
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
I gave you one suggestion:

You might want to look into a signed applet.


And in one of your other threads, I suggested zipping up all the files that the user generates and offering them as one dowload.

Beyond that, there isn't much someone on a forum can do for you.
You may also want to re-visit your requirements to make sure they're compatible with the technology you're working with. The web has it's limitations.
 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
how make all files in to zip and get download
 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi All,

Pls Clarify this it's very urget...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
I think this is being handled in your other post on the same topic.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!