Insert BLOB Data Using Stream Object, ASP

kevinkcw used Ask the Experts™
Can someone provide an example of inserting data into a MySQL database from data uploaded using a form, which uses the Stream object, in ASP?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004

I have a VB example of using the stream object at

You should be able to modify it to your needs.

Mike Hillyer



Thanks! There's just one problem with modifying your example. I haven't been able to get the data into the stream object from form data. Your example uses the .LoadFromFile method to load data from a flat file. Using the .Write method to take form data and add it to the Stream object just hasn't worked for me. I get an "Arguements are of wrong type..." error. So I use the text type of stream and the .WriteText method, and I don't get an error, but I can't upload the stream to the database because it's of the wrong type for the MediumBlob column.

Anyway, I was hoping for a more precise example. Something that uses the Stream Object to upload from form data submitted via a web page.

Top Expert 2004
Here is some code one reader of my article sent me, but I think it is for sending the blob to the browser:

Set ObjStream = Server.CreateObject("ADODB.Stream")
       objStream.Type = 1
       objStream.write mysqlFile_rs.fields("photo").value
       objStream.position = 0
       Response.ContentType = "image/jpeg"
       Response.BinaryWrite objStream.Read
       Set objStream = Nothing

My guess is you have to get the user to upload the file first somehow, then you insert the blob from the local file on the server (sorry, if I web program I pretty much just use PHP) I do not think there is any form field that could store a blob, so you will have to get the file from the browser to the server first I suspect.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial