Write a file to outputstream and supply a diferent name for it

  • Thread starter Thread starter Anton Sommer
  • Start date Start date
A

Anton Sommer

Hello folks,

I would like to let some authenticated users download certain files that
should not be downloadable for other users. All files are stored in one
directory with a unique filename supplied by the DB. I would feel better if
this directory was not directly accessible from the net (not in the path of
inetpub/application/.. )

I have tested three possibilities to let users download files, but each of
them have one thing that keeps me from using it:

1. Response.Redirect("/UPDTest/anton/Bild008.exe"): here the user gets a
filename suggested (what is vital for me) but the files are freely
accessible. ( If someone knows a possibility to change the free
accessibility please let me know)


2. Response.WriteFile("C:\temp\Bild 001.jpg"): here the user does not get
the right filename suggested but I need to do that! (of course it is the
filename of the aspx file)


3. Copy the file from the inaccessible directory to an accessible
directory, rename the file, use response.redirect to download it and delete
the file then after a certain period. But I can only delete the file after a
fixed period of time without knowing if the download has already completed
nor can I keep other users from downloading the file in that very period nor
can I keep the same user from downloading the file again without tracking it
in the application. Does anyone know a solution for that?


So what are your suggestions on that and are there other possibilities to
achieve what I am trying to do?


Thanks

Anton
 
You can write to the HTTP stream directly. The biggest hurdle is ensuring
any type you are "downloading" has a MIME type in the web server, or it will
be downloaded as garbage. I would watch how big of a file you "download" via
this method, as timeout is a potential (not present in links, but will be in
downloading from a page).

Another option is creation of a download manager application that takes
encrypted links and downloads. A clever hacker can figure out the true
location, but it will take some sniffing or decomposition of your download
manager. Timeout is not an issue in this case.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Thank you Gregory for answering,



Cowboy (Gregory A. Beamer) said:
You can write to the HTTP stream directly. The biggest hurdle is ensuring
any type you are "downloading" has a MIME type in the web server, or it will
be downloaded as garbage. I would watch how big of a file you "download" via
this method, as timeout is a potential (not present in links, but will be in
downloading from a page).

How would I set the MIME type individually and how would I set the file name
suggested to the user?

Thank you


Anton
 
Back
Top