ASP +Load Image File in SQL Server Database

I am trying to develop an app where we sell information that can be downloaded over the web, so it has to be secure but it also has to allow for disconnects.  i was thinking of loading the files into an image field in sql
server but i'm not sure how to tie it all together.  is it possible to download an image file say from an asp page that hits the sqlserver database?  would you first have to write this file from the database to the
hard disk  and then start the download? For instance if i had a compressed (winzip) file stored in an image field in  sql could i access it with an asp page and have  it downloaded directly to the user.  So if the web user points his browser to the asp page he should then be promted to save the file.  any help(especially  sample code) would be much appreciated.

thanks
afridaysAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
raizonConnect With a Mentor Commented:
give this a try.

to save room I'll only show the code that implements the

<%
'get the users ID first.  

'get the image and display the image

'write out form to store the userID
response.write "<form name=frmUser>"
response.write "<input type=hidden name=userID value=" & userID & ">"
response.write "</form>"

%>
<body onUnload="JavaScript: window.open('delete.asp?' + document.frmUser.userID.value,'myWindow', 'height=200, width=200, toolbars=0, scrollbar=0');>
0
 
raizonCommented:
Instead of storring the file itself in SQL server.  Store the location of the file in SQL server.
0
 
pure032398Commented:
raizon's suggestion is good, but i think u'll need to go one step further, my friend.

it sounds like u want to make it so that people can grab the image, either by downloading OR showing the image in an HTML page (then they right click => save pciture as)

either way, if i know the original location of the pic, then i can tell anyone else to grab that pic.

U might want to grab the pic location from the database and then copy that pic to a temp location, renaming it something weird (like picname & Now() & ".gif" or something..) and clearing that folder every week / month. That way, no one knows the original location of the pics, nor the original pics names.

if the downloaded information is text, then the same theory can be applied. of course, u don't really need a temp page .. the content is dynamic so if anyone tries to connect to the page, there will be no content (the content is dynamic remember .. dependant upon an input parameter).

anyways, this is getting long.

good luck

-PK-
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
raizonCommented:
>>if i know the original location of the pic, then i can tell anyone else to grab that pic.

simpilest way of preventing that is to apply security to the directory that the images are kept in.  In your IIS (if thats what you are running) Turn off allow anonymous authentication and turn on Basic authentication.  Set a specific user for that directory.  Then even if someone else gets the location of the pic they would have to have the username ans password as well.  

Keep in mind that this is trusting those who have the username and password not to give it out.

If you don't want to provide that sort of trust then PK's suggestion is the way to go.
0
 
Göran AnderssonCommented:
You can have the data in the database. All you need is an asp page that gets it from the database, if the correct requirements are met (e.g. user is logged in).

The asp page only has to read the data from the database and response.write it. This way you don't have to store it in a file somewhere, and you have no problems with file permission.

You may also want to change the content type and/or the filename. Something like:

Response.ContentType = "application/msword"
Response.AddHeader "content-disposition","attachment; filename=myinfo.doc"
0
 
afridaysAuthor Commented:
reply to RAIZON

say you had 10,000 people register on your site, and i don't want any registered user to view the files of other members so would i have to create individual folders for each member, with autentication that is specific to
them?  I guess if that is  the solution it would be possible to dynamically set up a folder when they set up a user account.  it seems like a lot of folders to manage.  After they successfully downloaded the files i would
then want to programatically delete them.

this seems like a lot of overhead.  basically we create a folder, populate the folder with data that is stored in sql,delete the data after a specific
time period.

would it be better to store the files in one non-browsing directory perhaps
with a guid for a file name and then email the user the link to download?

thanks for any input
0
 
raizonCommented:
With your needs being  specific users and specific files for that user then my previous suggestion would not be the way to go.

>>would it be better to store the files in one non-browsing directory perhaps
with a guid for a file name and then email the user the link to download?


This would be a good route to go but then you have the same issue where if the user gives someone else the path to the image they could still view it.


You could dynamically build the page with the link to the image and have the users ID in that page.  Create a function that when the onUnload event is called in posts the users ID to another page that will then perform all your clean ups needed.

Just a thought.

Raizon
0
 
afridaysAuthor Commented:
Raizon:
i'm not quite sure how to implement your response.  probably beyond the scope of this question. i think in reality if the end user wants to share
the file he is downloading there isn't much i can do.  Our product is environmental maps and data in pdf format.

have you seen any sample code with your suggested implemntation?

thanks
0
 
raizonCommented:
then in your delete.asp perform any cleanups necessary.

>>i think in reality if the end user wants to share the file he is downloading there isn't much i can do.  

absolutly true.
0
 
Göran AnderssonCommented:
Why not drop the form? ;)

<%
'get the users ID first.  

'get the image and display the image

%>
<body onUnload="JavaScript: window.open('delete.asp?<%=userID%>','myWindow', 'height=200,
width=200, toolbars=0, scrollbar=0');>
0
 
afridaysAuthor Commented:
TO:  Raizon, GreenGhost and Pure

Thanks for all the help.   I got a little busy and won't be able to get to it (implementing the code) until this weekend.   I'll let you know how it goes.
Thanks,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.