Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I store & retrieve a file from a table using asp

Status
Not open for further replies.

krish1980

Programmer
Feb 27, 2002
20
US
i'm able to upload a file into a directory. if i were to store the file into a table how would i retrieve the file back from the table. the file type could be image or .doc or spreadsheet or html. pls. help me in this regard. thanks
 
How are you doing the upload - i.e. what server side software is receiving the file.

If you're not familiar with this whizz over to persits who have something called ASPUpLoad - there is a demo version you can download, shove on your webserver and try out.

This comes with quite a few working examples - well worth a go.

FWIW I generally try to avoid storing uploaded files in any kind of a table - store them in a sensible dir structure and
manage them that way.

regards
Griff
[smile]
 
i'm using sql server as the back end. i've downloaded asp upload as instructed by u from microsoft site & am able to upload into a directory over the site. But isn't there any advantage in storing it in a database. anyhow my boss insists on storing it in a database as to avoid manual deletion to overwrite the file. pls. do help me how i can store it in a column name as well as download the image or doc or html file as such.

thanks for ur asp upload suggestion.
 
I had an idea that there was an example in the stuff that comes with ASPUpload, I'll have a look in a bit.

There are two or three disadvantages with placing the data directly into the tables.

1) If you spoil your database, your images will all be lost.
2) The database size may well become huge (GB in some cases)
3) It will take longer to upload and retrieve the information.

The ASP stuff will allow you to do 'pseudo logins' which means the images can be placed somewhere that accidental damage cannot occur.

I'll see if I can find a code sample for what you want though.

Griff
[Smile]

 
On the persits site I found a manual section under the ASPUpload 3.0 heading...
In there I found this code for importing files into an ODBC
compliant database

<HTML>
<BODY>
<%
Set Upload = Server.CreateObject(&quot;Persits.Upload&quot;)
' Capture files
Upload.Save &quot;c:\upload&quot;

' Obtain file object
Set File = Upload.Files(&quot;THEFILE&quot;)

If Not File Is Nothing Then
' Build ODBC connection string
Connect = &quot;Driver={Microsoft Access Driver (*.mdb)};DBQ=&quot; & Server.MapPath(&quot;.\aspupload.mdb&quot;)

' If you use SQL Server, the connecton string must look as follows:
' Connect = &quot;Driver=SQL Server;Server=MYSERVER;UID=sa;PWD=xxxxxxxxx&quot;

' Build SQL INSERT statement
SQL = &quot;INSERT INTO MYIMAGES(image_blob, filename, description, filesize) VALUES(?, '&quot;
SQL = SQL & File.Filename & &quot;', '&quot;
SQL = SQL & Replace(Upload.Form(&quot;DESCR&quot;), &quot;'&quot;, &quot;''&quot;) & &quot;', &quot;
SQL = SQL & File.Size & &quot;)&quot;

' Save to database
File.ToDatabase Connect, SQL
Response.Write &quot;File saved.&quot;
Else
Response.Write &quot;File not selected.&quot;
End If
%>
</BODY>
</HTML>

For export...

<%
Set db = Server.CreateObject(&quot;ADODB.Connection&quot;)
db.Open Connect
SQL = &quot;SELECT * FROM MYIMAGES where id = &quot; & Request(&quot;id&quot;)
Set rs =db.Execute( SQL )
Response.ContentType = &quot;application/octet-stream&quot;
' let the browser know the file name
Response.AddHeader &quot;Content-Disposition&quot;, &quot;attachment;filename=&quot; & Trim(rs(&quot;filename&quot;))
' let the browser know the file size
Response.AddHeader &quot;Content-Length&quot;, rs(&quot;filesize&quot;)
Response.BinaryWrite rs(&quot;image_blob&quot;)
%>

Hope these help

Griff
[smile]

 
Thanks for ur code sample. i'll try that & let u know. thanks.
 
Thanks Mr. Griff.

I am able to do this with ur sample code. thanks for sending me the sample code as well. i think maintaing a proper dir. structure as suggested by you earlier is a better option.

thanks. Krishnamoorthy
krish1980@rediffmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top