Today I experimented with binary SQL objects. I started by storing the image in a table by making an AJAX request to encode a base64 image and displaying it with.
<img src="data:image/jpeg;base64,' + base64imageReturnedWithAjax + '">')
The image is displayed normally.
The web project I'm working on also requires downloading files (mostly PDF). Great, I thought I would save the PDF as a binary SQL object, also collect it from the server in the same way, and then somehow magically decode it for download at the other end.
Help!
At first I tried to decode it using the base64 jQuery decoder (https://github.com/carlo/jquery-base64) with:
$.base64.decode(base64fileReturnedWithAjax)
This causes the following error in the console:
Uncaught Cannot decode base64
_getbyte64
_decode
$.ajax.success
f.Callbacks.o
f.Callbacks.p.fireWith
w
f.support.ajax.f.ajaxTransport.send.d
, : ? , ! , SQL?
, ATfPT
EDIT: , -, db/server ( VB.NET). Fileblob - .
'Having connected to the table
While lrd.Read()
Dim fileBytes = CType(lrd("Fileblob"), Byte())
Dim stream = New MemoryStream(fileBytes, 0, fileBytes.Length)
Dim base64String = Convert.ToBase64String(stream.ToArray())
document.Add(base64String)
End While
Dim serializer As New JavaScriptSerializer()
Dim returnVal As String = serializer.Serialize(document)
Return returnVal