Controlling the filename of a downloaded file.

B

Ben Jessel

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?
 
A

Andy Fish

In the past I have had problems with content-disposition with some versions
of some browsers (probably IE5.0). my workaround was to ensure that the URL
ends in "/myfile.gif"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top