holzer Posted May 8, 2005 Posted May 8, 2005 ok, so i'm trying to put together an asp page and pull pictures that are stored in an access db. i have a showpict.asp that returns the picture using Response.BinaryWrite. so far so good, but the only thing i see are red x's. now when i define the content type as text and then open it in firefox, i can see that access appends some bit of data before the actual jpeg, mainly a few times the word "package" and the location the file was on my harddrive before i inserted it.i've done some searches and apparently this is normal behaviour for access, and i've even found a fix.. only that fix was for delphi, not asp, and my asp knowledge doesn't go as far as that i could convert it.so i was wondering if anyone knows of a way to get around this and just get a simple jpeg file out of the db just like it was when it went in? also, i seem to have a similar (even worse) problem when i try to upload a jpeg to the db from my page. might be that i'm doing it wrong, i'm using an <input type=file> tag and then just get the post data and upload it to the db without any further modification. however, these pics don't even open in access (the ones i manually inserted do), and when i do the same content type trick, i only see the location it came from with each letter seperated by a ':', no binary looking stuff whatsoever anyway, any help would be greatly appreciated, i'm really quite stuck here and i absolutely need to store those pic's INSIDE the DB.
mattofak Posted May 8, 2005 Posted May 8, 2005 Because the OLE data object format is not documented, you will need to look for the image header... this is always started with the hex char: $FFD8now that you know the hex char, you can go through the data stream from the server, and delete everything before hex $FFD8then you have your jpg picture... ill get back to you on your upload problem...
mattofak Posted May 8, 2005 Posted May 8, 2005 kk, for file upload... make sure that your column data is OLE, but it should be anyway, and use this form code...<form action="myupload.asp" method=post enctype="multipart/form-data"> submit this file: <input type=file name="userfile"><br> <input type=submit><br> </form>this should ensure the proper formating
PoloDude Posted May 8, 2005 Posted May 8, 2005 Wouldn't it be easier to upload the file to a folder and add a reference to your db where the file is stored?Otherwise you'll get a huge db-file ...
mattofak Posted May 9, 2005 Posted May 9, 2005 I know that in PHP the solution proposed by PoloDude is what is generally used, in fact, you have to actaully open a new filestream to get the contents of the oploaded file, whereas its much easier to just move the file. However, does a huge DBFile really matter if its properly optimized, not really... Unless it gets REALLY big, or course this all depends on the system your using... I was thinking a bit however, and do you really want to use an Access DB, MySQL works perfectly fine with pictures, push and shove... The catch is to work with the MySQL Driver you need to be running .NET...
holzer Posted May 9, 2005 Author Posted May 9, 2005 thx for your replies.. the thing is i'm making this thing for a friend of mine, it's a school assignment and it needs to use ASP and access.. if it wouldve been for me, i'd have used a decent db from the start... the reason im storing the files in the db is mainly for ease of management (delete record = delete image, etc) and because i'm not that good at asp, i thought getting to know the filesystem object would become an extra burden... the size of the db is not really a big issue since it's only administrators who will have the possibility to upload files. anyway, now that i have will have to manually search for the image, i might have to rethink that whole thing..
holzer Posted May 9, 2005 Author Posted May 9, 2005 hmm i've tried adding the enctype="multipart/form-data" property to my form (which is as far as i can see the only difference between your code and mine), and now whenever i actually attach a file, i get a "cannot find server or DNS error" is there like a setting i need to make in IIS to enable file uploads?and when i don't add a picture, i get a "Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression". taking out the picture part doesn't help it, so i suppose adding the enctype property also converts the other (text) fields to something else than string format... Edit: if I Response.Write the resulting SQL string, i get INSERT INTO tblProducts ( ProdName, CatID, ProdPrice, ProdStock, ProdShortDesc, ProdDesc, ProdPict) VALUES ('','','','','','','')where did all my form data go
mattofak Posted May 9, 2005 Posted May 9, 2005 You dont really have to search for the image, just the beginning of the image header... its a standard stream search call for hex $ffd8something like this Private Function FindJPG(ByVal mPicStream As String) As String Dim mPic As String Dim mSearchString As String Dim iPos As Integer = 1 Dim iFound As Boolean Do Until iFound = True mSearchString = Mid(mPicStream, iPos, 1) & Mid(mPicStream, iPos + 1, 1) If mSearchString = ChrW(255) & ChrW(216) Then iFound = True Else iPos = iPos + 1 End If Loop mPic = Right(mPicStream, Len(mPicStream) - (iPos - 1)) Return mPic End Functionand yes, adding it does change the whole form to multipart mime... hmm, how to get around it... ill think on it...
ramone_johnny Posted August 3, 2005 Posted August 3, 2005 You might want to try this...probably solve your problem in a nutshell.http://www.pscode.com/vb/scripts/ShowCode....d=6447&lngWId=4Also I wouldnt make a habit actually storing ANY images in an access DB. Access is clumsy and will only handle so much. The trick is to store the *path* to the image folder location.IEDIM myimagesmyimages = "mysite/images/"Then simply call the desired image by either a unique ID or something then stick the myimages in front of it. Understand?RJ
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now