Subject: storing an image in a database
Posted By: nagdandey Post Date: 12/16/2003 4:26:02 AM
Hai,
Now,I am learning ASP through MSAccess Database.I want to store and retrive an image.
To store an image i used OLE Object in the MSaccess database.

To store an image through ASP,i used the HTML \"input\" tag of type \"file\".we can specify the file name through brouse button.the output of the upload file is the rawdata + image,i seperated the image and stored in a variable.while
storing this in a database through asp code,I am getting this error.


Error Type:
Provider (0x80040E21)
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
/uploadfile.asp, line 33



so,give me the code for that or correct the code.
my id is nagdandey@rediffmail.com

This is the code :

1)file.HTML

<FORM NAME="oForm"
ACTION="uploadfile.asp"
ENCTYPE="multipart/form-data"
METHOD="post">
<pre>
<INPUT TYPE="file" NAME="oFile1" Accept="image/*">

<br>
<INPUT TYPE="submit" VALUE="Upload File">
</pre>

</FORM>


2)uploadfie.asp [error]

<%
option explicit
Dim FormSize,FormData,bnCRLF,Divider,DataStart,DataEnd

FormSize = Request.TotalBytes
FormData = Request.BinaryRead(FormSize)
bnCRLF = chrB(13) & chrB(10)
Divider = LEFTB(FormData,INSTRB(FormData,bnCRLF) - 1)
DataStart= INSTRB(FormData,bnCRLF & bnCRLF) + 4
DataEnd = INSTRB(DataStart + 1,FormData,Divider) - DataStart
Response.ContentType = "image/gif"
Dim Image
image = MIDB(FormData,DataStart,DataEnd)
'Response.BinaryWrite image
'Response.End
%>
<html>
<body>

<%

Dim con,conStr,rs,sQl
conStr =\"Provider =Microsoft.Jet.OLEDB.4.0;Data Source =C:\work\nag\website\databases\raw.mdb;Persist Security Info = False "

Set con = Server.CreateObject("ADODB.Connection")
con.open conStr

Set rs =Server.CreateObject("ADODB.RecordSet")
rs.open "select * from rawtable where 1=0",con,0,2,0
'If request.Servervariables("REQUEST_METHOD") = "POST" Then
rs.addNew

rs(1) =image
rs.UpdateBatch
dim sql1
sql1="insert into rawtable (rawtext) values(" + image +")"
'con.execute(sql1)
Response.write("<center><b>Inserted Successfully</b></center>")
'End If

%>
</Body>
</html>

3)database

Name of the database is raw.mdb

in the raw.mdb,a file named rawtext table is there.
the rawtext table contains two fields rawid and rawtext.

ok.
please help me.
WAITING FOR UR REPLY.
Bye.


Reply By: stu9820 Reply Date: 12/16/2003 1:06:29 PM
You really don't want to store image files in an Access database.  You can create a function that removes the .gif extension and stores the image name in the db and also sends the file to an upload/images folder. If you need to view the image you can then append the .gif extension when you pull the image name out of the db.

Reply By: nagdandey Reply Date: 12/17/2003 4:39:34 AM
quote:
Originally posted by stu9820

You really don't want to store image files in an Access database.  You can create a function that removes the .gif extension and stores the image name in the db and also sends the file to an upload/images folder. If you need to view the image you can then append the .gif extension when you pull the image name out of the db.

 



quote:

        I don't know how to remove .gif extention from the file.please send the code for me.It is part of my project.I am doing a project in asp with northwind database.what I have to do is to display the data of the tables.if it is an image,i want to display the image.If u know the code for that please help me.I need taht one.
Ok.
Bye





Go to topic 7669

Return to index page 985
Return to index page 984
Return to index page 983
Return to index page 982
Return to index page 981
Return to index page 980
Return to index page 979
Return to index page 978
Return to index page 977
Return to index page 976