How to json marshal Blob type?

How to json marshal Blob type from database?
And how to convert blob to images/file in golang?

What database do you use? What is the database type of the column?

It is hard to answer you question without more details.

Hi Lutzhorn,

Im using Database SQL Server, type column varbinary(MAX)

“Blobs” are typically represented as a []byte in Go. By default those will JSON serialize with base64 encoding. You would convert the blob to an image by using the appropriate image decoder - the standard library has support for gif, png, jpeg. You only need to do that if you want to do something with the image as an image - rescale it, draw text on it, etc. To write it out to a file you would use the I/O operations in the OS package, or (simplest) the ioutil.WriteFile convenience function.

If this does not answer your question, please be more specific and show some code. :slight_smile:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.