How to download an image as base64 from db (not from a folder) using c# .net

How to download an image as base64 from db (not from a folder) using c# .net

ASWSASWS Posts: 43Questions: 4Answers: 0

sorry, initially posted this under the wrong category...

-> .net mvc, within the controller action, I have the following question:

on server side I retrieve a blob "avatar_pic" from my db "table1" and I want to send it to the client... -> I store (avatar) images in a db table as blob, not as files on the server, so the other given examples here dont work for my setup.

As far as I understood, I should then declare something similar to this:
.Field(new Field("table1.avatar_pic")
in order to transfer my server side base64 string with ajax.
(something I converted beforehand from a blob to a base64 string in the controller action)

But in the end how does this "new field" have to be declared properly in the .net controller? Any explicit example would be really welcome, I did spend quite some time reading most likely all the wrong stuff, feeling quite stupid already...

So again for your understanding, I acces my e.g. "table1" and retrieve a blob directly from the db, during the controller action... I then do convert it to a base64 string, so far so good, but after this I'm stuck with something like this:

.Field(new Field("table1.avatar_pic"),

which doesnt seem to work here, except for a basic string field.

-> on the datatable client side I then want to retrieve and render this base64 string, like in this example:

{ data: "table1.avatar_pic", render: function (data, type, row) {
return '<img src="data:image/png;base64,'+data+'" width="50px" height="50px">'; }}

but as said above, I cant get this data to client side.

=============================================================================================

so, to sum it up, I would just need a short example of some c# mvc controller syntax, in order to send a base64 string to the client... (and subsequently in the opposite direction (upload) too actually) - many thanks in advance!!!

Sign In or Register to comment.