top
(README.md)
## Media Library

Media Library is a [Golang](http://golang.org/) library that supports the upload of files/images to a filesystem or cloud storage. The Plugin includes cropping and resizing features for images.

[![GoDoc](https://godoc.org/github.com/qor/media_library?status.svg)](https://godoc.org/github.com/qor/media_library)

## Usage

Media Library is dependant on [GORM-backend](https://github.com/jinzhu/gorm) models as it is using GORM's callbacks to handle file processing, so you will need to register callbacks first:

```go
import "github.com/jinzhu/gorm"
import "github.com/qor/media_library"

DB, err = gorm.Open("sqlite3", "demo_db") // [gorm](https://github.com/jinzhu/gorm)

media_library.RegisterCallbacks(&DB)
```

Add Media Library support to structs:

```go
// upload file to FileSystem
import "github.com/qor/media_library"

type Product struct {
	gorm.Model
	Image media_library.FileSystem
}

// Upload file to s3
import "github.com/qor/media_library/aws"

type Product struct {
	gorm.Model
	Image aws.S3
}
```

And you're done setting up! You could the use it like this:

```go
var product Product

if productImage, err := os.Open("product_image.png"); err == nil {
	product.Image.Scan(productImage)
}

DB.Save(&product)

// Get image's url, will be s3 url if it is uploaded to s3
product.Image.URL()
```

## Advanced Usage

```go
// Resize images into different sizes when saving images
type ProductIconImageStorage struct{
	media_library.FileSystem
}

func (ProductIconImageStorage) GetSizes() map[string]media_library.Size {
	return map[string]media_library.Size{
		"small":    {Width: 60 * 2, Height: 60 * 2},
		"small@ld": {Width: 60, Height: 60},

		"middle":    {Width: 108 * 2, Height: 108 * 2},
		"middle@ld": {Width: 108, Height: 108},

		"big":    {Width: 144 * 2, Height: 144 * 2},
		"big@ld": {Width: 144, Height: 144},
	}
}

// Get image's url with style
product.Image.URL("small")
product.Image.URL("big@ld")
```

## [Qor Support](https://github.com/qor/qor)

[QOR](http://getqor.com) is architected from the ground up to accelerate development and deployment of Content Management Systems, E-commerce Systems, and Business Applications and as such is comprised of modules that abstract common features for such systems.

Media Library could be used alone, but it works very nicely with QOR (as a QOR Plugin), if you have requirements to manage your application's data, be sure to check QOR out!

[QOR Demo:  http://demo.getqor.com/admin](http://demo.getqor.com/admin)

[Media Library Demo with QOR](http://demo.getqor.com/admin/products/1)

## License

Released under the [MIT License](http://opensource.org/licenses/MIT).

Imported by 54 package(s)

  1. github.com/8legd/HugoCMS/qor
  2. github.com/8legd/hugocms/qor
  3. github.com/8legd/hugocms/qor/models
  4. github.com/alfatraining/i18n/exchange_actions
  5. github.com/andboson/qor-admin-test/config/admin
  6. github.com/andboson/qor-admin-test/db
  7. github.com/andboson/qor-admin-test/db/migrations
  8. github.com/azumads/selenium/app
  9. github.com/chazzuka/qor-example/app/models
  10. github.com/chazzuka/qor-example/config/admin
  11. github.com/chazzuka/qor-example/db
  12. github.com/chazzuka/qor-example/db/migrations
  13. github.com/dwarvesf/delivr-admin/app/model
  14. github.com/dwarvesf/delivr-admin/config/admin
  15. github.com/dwarvesf/delivr-admin/config/api
  16. github.com/dwarvesf/delivr-admin/db
  17. github.com/dwarvesf/media_library/aliyun
  18. github.com/dwarvesf/media_library/qiniu
  19. github.com/mmanjoura/qor-app/media_library/aliyun
  20. github.com/mmanjoura/qor-app/media_library/aws
  21. github.com/mmanjoura/qor-app/media_library/qiniu
  22. github.com/mmanjoura/qor-example/app/models
  23. github.com/mmanjoura/qor-example/config/admin
  24. github.com/mmanjoura/qor-example/db
  25. github.com/mmanjoura/qor-example/db/migrations
  26. github.com/mstat/qor-example/app/models
  27. github.com/mstat/qor-example/config/admin
  28. github.com/mstat/qor-example/db
  29. github.com/mstat/qor-example/db/migrations
  30. github.com/oywc410/qor-example/app/models
  31. github.com/oywc410/qor-example/config/admin
  32. github.com/oywc410/qor-example/db
  33. github.com/oywc410/qor-example/db/migrations
  34. github.com/pfcoder/media_library/aliyun
  35. github.com/pfcoder/media_library/aws
  36. github.com/pfcoder/media_library/handlers/vips
  37. github.com/pfcoder/media_library/qiniu
  38. github.com/qor/activity
  39. github.com/qor/i18n/exchange_actions
  40. github.com/qor/media_library/aliyun
  41. github.com/qor/media_library/aws
  42. github.com/qor/media_library/qiniu
  43. github.com/qor/qor-example/app/models
  44. github.com/qor/qor-example/config/admin
  45. github.com/qor/qor-example/db
  46. github.com/qor/qor-example/db/migrations
  47. github.com/steveoc64/qor-example/app/models
  48. github.com/steveoc64/qor-example/config/admin
  49. github.com/steveoc64/qor-example/db
  50. github.com/steveoc64/qor-example/db/migrations
  51. github.com/youryharchenko/qor-example/app/models
  52. github.com/youryharchenko/qor-example/config/admin
  53. github.com/youryharchenko/qor-example/db
  54. github.com/youryharchenko/qor-example/db/migrations

Imported only in test by 17 package(s)

  1. github.com/756445638/media_library
  2. github.com/alfatraining/admin
  3. github.com/derlaft/admin
  4. github.com/dwarvesf/admin
  5. github.com/dwarvesf/media_library
  6. github.com/ethanfrey/admin
  7. github.com/grengojbo/admin
  8. github.com/mmanjoura/qor-app/media_library
  9. github.com/nguyendangminh/admin
  10. github.com/oywc410/qor/admin
  11. github.com/pfcoder/admin
  12. github.com/pfcoder/media_library
  13. github.com/qor/admin
  14. github.com/retailify/admin
  15. github.com/suifengRock/qor/admin
  16. github.com/thanzen/qor/admin
  17. github.com/zhaodj/admin

Imports 8 package(s)

  1. github.com/jinzhu/gorm
  2. github.com/qor/qor/resource
  3. github.com/qor/serializable_meta
  4. github.com/jinzhu/inflection
  5. github.com/qor/qor
  6. github.com/qor/qor/utils
  7. github.com/qor/admin
  8. github.com/disintegration/imaging

Test imports 1 package(s)

  1. github.com/qor/qor/test/utils