views:

44

answers:

2

Hey guys,

I have a server running and a web client accessing it to download file.

When I access

server/.../MyFile/

the file named "MyFile" is downloaded and a pop up "Open , Save as" is displayed. When I click save as, the proposed name is "MyFile".

How do I change it to another name?

p.s. I can not change /MyFile to /SomeOtherFile, since this link contains another file each time, depending on the work done by the server. Thus, the proposal "MyFile" in save as in meaningless. I would prefer to propose the name of the file I actually downloaded.

Thanks Yura

+1  A: 

You need to send this header with it:

content-disposition: attachment; filename="somefilename.ext"

In Asp.Net it is the following. But what language, framework and server are you using?

context.Response.AddHeader("content-disposition", "attachment; filename=\"somefilename.txt\"");

If you use Java servlets it is something like this: (Not used Java for some time)

protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    response.setHeader("content-disposition", "attachment; filename=\"somefilename.ext\"");

    //Write the file to response and maybe set content type
}
lasseespeholt
My server is written in Java. (I use Jetty)How would this code look like for me?
Yura
@Yura, maybe something like that. Otherwise, post some of your get-file-code.
lasseespeholt
Thanks, thats the answer :)
Yura
A: 

All web servers have mapping file extension, if a request has made web server lookup for the file extension in their mapping table, if they found, they handed it to the appropriate handler like all *.aspx files handed to the aspnet_isapi.dll and the control has transferred to that handler but normal files like .txt, or .png does not handle with IIS if you want to take control of them you should add that file extension to web server mapping table and map that extension to your desired handler and then you can take control of it

You can find plenty of useful article by googling (mime type mapping extension)
hope it helps !

Ehsan