feat: save images in database
This commit is contained in:
parent
275fe53c90
commit
7aa372dca1
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -24,3 +24,5 @@ go.work
|
||||||
TODO
|
TODO
|
||||||
.env
|
.env
|
||||||
test.db
|
test.db
|
||||||
|
|
||||||
|
public/*
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -6,6 +6,9 @@ require (
|
||||||
github.com/dchest/uniuri v1.2.0
|
github.com/dchest/uniuri v1.2.0
|
||||||
github.com/gofiber/fiber/v2 v2.52.5
|
github.com/gofiber/fiber/v2 v2.52.5
|
||||||
github.com/h2non/bimg v1.1.9
|
github.com/h2non/bimg v1.1.9
|
||||||
|
github.com/joho/godotenv v1.5.1
|
||||||
|
gorm.io/driver/sqlite v1.5.6
|
||||||
|
gorm.io/gorm v1.25.10
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -13,7 +16,6 @@ require (
|
||||||
github.com/google/uuid v1.5.0 // indirect
|
github.com/google/uuid v1.5.0 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/joho/godotenv v1.5.1 // indirect
|
|
||||||
github.com/klauspost/compress v1.17.0 // indirect
|
github.com/klauspost/compress v1.17.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
@ -24,6 +26,4 @@ require (
|
||||||
github.com/valyala/fasthttp v1.51.0 // indirect
|
github.com/valyala/fasthttp v1.51.0 // indirect
|
||||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.15.0 // indirect
|
golang.org/x/sys v0.15.0 // indirect
|
||||||
gorm.io/driver/sqlite v1.5.6 // indirect
|
|
||||||
gorm.io/gorm v1.25.10 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type KonuluKonum struct {
|
type KonuluKonum struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
URI string
|
URI string
|
||||||
ImageURI string
|
Image []byte `gorm:"type:BLOB"`
|
||||||
Loc string
|
Loc string
|
||||||
AuthorName string
|
AuthorName string
|
||||||
Description string
|
Description string
|
||||||
|
|
|
@ -86,12 +86,13 @@ func main() {
|
||||||
|
|
||||||
fmt.Println(imageUri)
|
fmt.Println(imageUri)
|
||||||
|
|
||||||
db.Create(&models.KonuluKonum{URI: "sample", ImageURI: imageUri, Loc: "sample", AuthorName: "sample", Description: "sample", UnlockedCounter: 0})
|
db.Create(&models.KonuluKonum{URI: "sample", Image: newImage, Loc: "sample", AuthorName: "sample", Description: "sample", UnlockedCounter: 0})
|
||||||
|
|
||||||
var konuluKonum models.KonuluKonum
|
var konuluKonum models.KonuluKonum
|
||||||
db.First(&konuluKonum)
|
db.First(&konuluKonum)
|
||||||
|
|
||||||
fmt.Println(konuluKonum.ImageURI)
|
// Save image
|
||||||
|
bimg.Write("./public/storedImage.webp", konuluKonum.Image)
|
||||||
|
|
||||||
db.Delete(&konuluKonum)
|
db.Delete(&konuluKonum)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user