top
(README.md)
# Media Library OSS

Use [OSS](https://github.com/qor/oss) as backend to store medias

# Usage

```go
import (
	"github.com/qor/media/oss"
	"github.com/qor/oss/filesystem"
	"github.com/qor/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

```go
// 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](http://opensource.org/licenses/MIT).

Imported by 31 package(s)

  1. github.com/GazeboXu/qor-example/app/admin
  2. github.com/GazeboXu/qor-example/config
  3. github.com/GazeboXu/qor-example/models/products
  4. github.com/GazeboXu/qor-example/models/users
  5. github.com/Jungju/admin/tests/dummy
  6. github.com/Jungju/i18n/exchange_actions
  7. github.com/fundon/admin/tests/dummy
  8. github.com/jungju/admin/tests/dummy
  9. github.com/mmanjoura/cms-api/app/admin
  10. github.com/mmanjoura/cms-api/config
  11. github.com/mmanjoura/cms-api/models/products
  12. github.com/mmanjoura/cms-api/models/users
  13. github.com/mmanjoura/qor-app/admin/tests/dummy
  14. github.com/mmanjoura/qor-app/i18n/exchange_actions
  15. github.com/mmanjoura/qor-app/media/asset_manager
  16. github.com/mmanjoura/qor-app/media/media_library
  17. github.com/mmanjoura/qor-app/qor-example/config
  18. github.com/qor/admin/tests/dummy
  19. github.com/qor/media/asset_manager
  20. github.com/qor/media/media_library
  21. github.com/qor/qor-example/app/admin
  22. github.com/qor/qor-example/models/products
  23. github.com/qor/qor-example/models/users
  24. github.com/reechou/erp/app/models
  25. github.com/reechou/erp/config/admin
  26. github.com/reechou/real-erp/admin
  27. github.com/uzmo/media/asset_manager
  28. github.com/uzmo/media/media_library
  29. github.com/wfxiang08/admin/tests/dummy
  30. github.com/whimsycwd/qor-example/app/models
  31. github.com/whimsycwd/qor-example/config/admin

Imported only in test by 4 package(s)

  1. github.com/glebtv/admin
  2. github.com/mmanjoura/qor-app/media/oss
  3. github.com/uzmo/media/oss
  4. github.com/vedhavyas/admin

Imports 4 package(s)

  1. github.com/qor/qor/utils
  2. github.com/qor/media
  3. github.com/qor/oss
  4. github.com/qor/oss/filesystem

Test imports 4 package(s)

  1. github.com/jinzhu/configor
  2. github.com/jinzhu/gorm
  3. github.com/qor/qor/test/utils
  4. github.com/qor/oss/s3