Controlling the filename of a downloaded file.

From: Ben Jessel (ben.jessel_at_morpheme.co.uk)
Date: 11/25/03


Date: 25 Nov 2003 06:55:45 -0800

I have a requirement where files, which are stored in a repository
with names such as 1.jpg, 2.gif, 3.pdf must be presented for download
by the user, but with different filenames from how they are called in
the repository.

The reason being that the internal repository of the system arranges
and stores files by giving them an index number. Their real "name" as
far as the user is concerned is held in a mapping database.

The reason we do this is because:

 a) we may not want the user to directly access the file from within
the
    repository; my servlet provides the ability to impose security
constraints,
    and enable an element of control when accessing the file.
 b) It enables us to have files with the same "name" ( as far as the
customer's
    concerned ) to be stored without having to resort to some
complicated
    create-some-nested-sub-directory-when-a-file-of-the-same-name-is-
    encountered.
 c) Filenames which have the same ID as the "objects" to which they
relate to,
    enable easier business logic and archiving implementations.

However, I want the user to be presented with the original filename
when the come to download the file. So if the file was initially
"uploaded" as "myfile.gif", it is stored as, say 1.gif. When a user
downloads it, the link should be something like
/servlets/accessRepository?id=1&repository=articles, and when the file
downloads, the user gets an option to save it as, "myfile.gif".

I can set the mime type of my servlet o.k, and I know how to spool
bytes to an output, but the name of the file seems to always be the
name of the link. Is there anyway to specify what the name of the file
will be?