package
0.0.0-20190717155653-b7a9f985dc68
Repository: https://github.com/kisrobot/media.git
Documentation: pkg.go.dev
# README
Media Library OSS
Use OSS as backend to store medias
Usage
import (
"github.com/kisrobot/media/oss"
"github.com/kisrobot/oss/filesystem"
"github.com/kisrobot/oss/s3"
awss3 "github.com/aws/aws-sdk-go/service/s3"
)
type Product struct {
gorm.Model
Image oss.OSS
}
func init() {
// OSS's default storage is directory `public`, change it to S3
oss.Storage = s3.New(&s3.Config{AccessID: "access_id", AccessKey: "access_key", Region: "region", Bucket: "bucket", Endpoint: "cdn.getqor.com", ACL: awss3.BucketCannedACLPublicRead})
// or change directory to `download`
oss.Storage = filesystem.New("download")
}
Advanced Usage
// change URL template
oss.URLTemplate = "/system/{{class}}/{{primary_key}}/{{column}}/{{filename_with_hash}}"
// change default URL handler
oss.DefaultURLTemplateHandler = func(option *media_library.Option) (url string) {
// ...
}
// change default save handler
oss.DefaultStoreHandler = func(path string, option *media_library.Option, reader io.Reader) error {
// ...
}
// change default retrieve handler
oss.DefaultRetrieveHandler = func(path string) (*os.File, error) {
// ...
}
// By overwritting default store, retrieve handler, you could do some advanced tasks, like use private mode when store sensitive data to S3, public read mode for other files
License
Released under the MIT License.
# Variables
DefaultRetrieveHandler used to retrieve file.
DefaultStoreHandler used to store reader with default Storage.
DefaultURLTemplateHandler used to generate URL and save into database.
Storage the storage used to save medias.
URLTemplate default URL template.