Azuma Daisuke b6cc4ddf9f Update integration_test.go il y a 1 an
..
filesystem abd359076b fix organization name changed il y a 1 an
integration b6cc4ddf9f Update integration_test.go il y a 1 an
media_library 3e0750fb35 Add QorPreviewMaxSize to generate thumbnails il y a 1 an
oss abd359076b fix organization name changed il y a 1 an
views 3558b4f980 fix merge il y a 1 an
vips abd359076b fix organization name changed il y a 1 an
README.md 5943f529ce update media readme il y a 3 ans
base.go f39d62dd25 upgrade gorm il y a 1 an
handlers.go dc6735fd29 Fix upload and crop images il y a 2 ans
media.go f6422aa649 Use GORM 2.0 il y a 3 ans
upload.go 3121fdad18 show crop error il y a 1 an
utils.go abd359076b fix organization name changed il y a 1 an

README.md

Media Library

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:

  • cropping and resizing features for images.
  • optional multiple sizes for each media resource.
  • Accessibility helpers.
File Types

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

Usage

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,
})


Use media box in a model

type Product struct {
	gorm.Model
	HeroImage     media_library.MediaBox `sql:"type:text;"`
}

Configure media box


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,
            },
        },
    })

License

Released under the MIT License.