0

I would like to insert a binary value into the database without using FileUpload. I searched for tutorials, samples and i saw only codes like:

  Dim fs As Stream = FileUpload1.PostedFile.InputStream
  Dim br As New BinaryReader(fs)
  Dim bytes As Byte() = br.ReadBytes(fs.Length)

But, I have already a file/data in my asp:Image> with the use of a Canvas,

var dataURL = canvas.toDataURL();

which is data:image/png;base64,iVBORw0KGgoAAAANSU...etc.

I am inserting it already in the database by putting it in a textarea

 document.getElementById("TextArea1").value = dataURL;

and in my code behind.

 Dim sqlComm As New SqlCommand("INSERT INTO patient_data.dbo.tbPatientImage (HospNum,IdNum,DoctorID,TransDate,PatImage,FileType,FileSize) VALUES (@HospNum,@IDNum,@DoctorID,getdate(),@PatImage,'image/jpg','0')", sqlConn)
 Dim photoParam As New SqlParameter("@PatImage", SqlDbType.VarChar)
 sqlcomm.photoParam.Value = TextArea1.Value
 sqlcomm.Parameters.Add(photoParam)
 sqlcomm.ExecuteNonQuery()

Yeah it is inserting but when i try to retrieve it on the database, it does not show anything.

Some files that were inserted by the use of Fileupload were retrieved and displayed correctly, but the inserted data:image/png;base64,iVBORw0KGgoAAAANSU...etc. doesn't work. What should i do? is there an easier/better way?

Dale
  • 159
  • 4
  • 20
  • data-uri to image conversion codes, might help you. So that you can check whether you can convert to proper image and take it from there? – Rohith Nair Aug 14 '14 at 09:00
  • can i convert data:image/png;base64 into a binary value? – Dale Aug 14 '14 at 09:08
  • 1
    I think two links might help you; I am not sure of which end you are trying to get to http://stackoverflow.com/a/4776378/458530 and https://gist.github.com/vbfox/484643. These snippets can help you – Rohith Nair Aug 14 '14 at 09:17

0 Answers0