xuxin ab4a2903f0 media: fix crop with hash MediaLibraryURL | 1 rok pred | |
---|---|---|
.. | ||
filesystem | 2 rokov pred | |
integration | 1 rok pred | |
media_library | 1 rok pred | |
oss | 2 rokov pred | |
views | 1 rok pred | |
vips | 2 rokov pred | |
README.md | 3 rokov pred | |
base.go | 2 rokov pred | |
handlers.go | 3 rokov pred | |
media.go | 3 rokov pred | |
upload.go | 1 rok pred | |
utils.go | 2 rokov pred |
Media is a Golang library that supports the upload of files/images/videos to a filesystem or cloud storage as well as linked videos (i.e. YouTube, Vimeo, etc.). The plugin includes:
Media accepts any and every file type, yet it associates certain file types as images or videos so as to provide helpers supporting those media's specific needs.
Images: .jpg, .jpeg, .png, .tif, .tiff, .bmp, .gif
Videos: .mp4, .m4p, .m4v, .m4v, .mov, .mpeg, .webm, .avi, .ogg, .ogv
Media depends on GORM models as it is using GORM's callbacks to handle file processing, so you will need to register callbacks first:
db, err := gorm.Open(postgres.Open(os.Getenv("DB_PARAMS")), &gorm.Config{})
media.RegisterCallbacks(db)
sess := session.Must(session.NewSession())
oss.Storage = s3.New(&s3.Config{
Bucket: os.Getenv("S3_Bucket"),
Region: os.Getenv("S3_Region"),
Session: sess,
})
type Product struct {
gorm.Model
HeroImage media_library.MediaBox `sql:"type:text;"`
}
import (
media_view "github.com/qor/qor5/media/views"
)
b := presets.New()
media_view.Configure(b, db)
p := b.Model(&Product{})
ed := p.Editing( "HeroImage")
ed.Field("HeroImage").WithContextValue(
media_view.MediaBoxConfig,
&media_library.MediaBoxConfig{
AllowType: "image",
Sizes: map[string]*media.Size{
"thumb": {
Width: 400,
Height: 300,
},
},
})
Released under the MIT License.