Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP +Load  Image File in SQL Server Database

Posted on 2001-08-26
11
Medium Priority
?
255 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:afridays
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 5

Expert Comment

by:raizon
ID: 6427064
Instead of storring the file itself in SQL server.  Store the location of the file in SQL server.
0
 
LVL 1

Expert Comment

by:pure032398
ID: 6427695
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
 
LVL 5

Expert Comment

by:raizon
ID: 6428515
>>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:Göran Andersson
ID: 6428534
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
 

Author Comment

by:afridays
ID: 6428819
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
 
LVL 5

Expert Comment

by:raizon
ID: 6428853
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
 

Author Comment

by:afridays
ID: 6430197
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
 
LVL 5

Accepted Solution

by:
raizon earned 400 total points
ID: 6432108
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
 
LVL 5

Expert Comment

by:raizon
ID: 6432118
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
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 6432586
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
 

Author Comment

by:afridays
ID: 6438728
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

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question