Answer the question
In order to leave comments, you need to log in
How to save and retrieve images from db using go?
The task is to save several pictures from one form field in the database and display them in html. I tried to save to the database in blob format, but now I can't decrypt and display these images. Several images from one input fall into one field of the database table. I was looking for answers to the question, it was said that you can also save images in a folder, and write the path to the file in the database. I would be glad to help with any of the methods, most importantly with an example of the go code (I did not find anything on the network other than php).
Answer the question
In order to leave comments, you need to log in
Here's what I did to save .xlsx files. It seems to work for pictures as well.
func DownloadFile(filepath, url string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
return err
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question