I want to send a json string with base64 encoded file in it from a client, basically it looks like this:
{
"data":"aGVscA==",
"filename":"file.txt"
}
And I wrote this struct:
type StoredFile struct {
Data []byte `json:"data"`
Filename string `json:"filename"`
}
Then I decode the json into the struct:
decoder := json.NewDecoder(request.Body)
storedFile := StoredFile{}
err := decoder.Decode(&storedFile)
And save it with gorm:
db.Create(&storedFile)
My question is:
- How do json package decode the base64 string to byte array? Does it treat it like plain text, because I know that the data size will be increased by 33% when it is encoded to base64 and if it is treated like text the 33% increase will still be there right?
- What kind of encoding does gorm use when it stores []byte to PostgreSQL database? Is it UTF-8? If not, how do I set the encoding to UTF-8?