ftm-pm / media-server
MediaServer is a micro application that receives an image file with filters and returns the path to this image and a collection of images with applied filters.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
pkg:composer/ftm-pm/media-server
Requires
- php: ^7.1.3
- ext-iconv: *
- gesdinet/jwt-refresh-token-bundle: ^0.3.2
- gfreeau/get-jwt-bundle: ^2.0
- guzzlehttp/guzzle: ^6.3
- lexik/jwt-authentication-bundle: ^2.4
- liip/imagine-bundle: 2.0.x-dev
- nelmio/cors-bundle: ^1.5
- sensio/framework-extra-bundle: ^5.1
- symfony/console: ^4.0
- symfony/flex: ^1.0
- symfony/form: ^4.0
- symfony/framework-bundle: ^4.0
- symfony/lts: ^4@dev
- symfony/maker-bundle: ^1.0
- symfony/monolog-bundle: ^3.2
- symfony/orm-pack: ^1.0
- symfony/security-bundle: ^4.0
- symfony/serializer: ^4.0
- symfony/swiftmailer-bundle: ^3.2
- symfony/twig-bundle: ^4.0
- symfony/validator: ^4.0
- symfony/yaml: ^4.0
- vich/uploader-bundle: ^1.7
Requires (Dev)
- symfony/dotenv: ^4.0
- symfony/var-dumper: ^4.0
Conflicts
This package is not auto-updated.
Last update: 2020-01-22 19:03:38 UTC
README
The MediaServer is a micro application that receives an image file with filters(or simple file) and returns the path to this image and a collection of images with applied filters (or path for simple file).
Russian documentation here.
Setup
The MediaServer is a symfony/skeleton application with packages for uploading and cropping images. Some bundles:
- VichUploaderBundle - uploading images
- LiipImagineBundle - creating preview images
- LexikJWTAuthenticationBundle - authorization JWT
- All bundles
Installation
Run the Composer command to create a new project
composer create-project ftm-pm/media-server my-project
Configuration
After installing, you need to set environment variables. You can see variables in the .env file.
Next step, run command to update database.
php bin/console d:s:u --force
In MediaServer, authorization was developed using JWT. You can see documentation here.
For create a new user, you can use any REST client. You should send a new request to http://my-project/api/register with parameters:
{
"username": "johndoe",
"password": "test",
"email": "johndoe@example.com"
}
or using curl
curl -X POST http://my-project/api/register -d username=johndoe -d password=test -d email=johndoe@example.com
After the confirmation email, get token. Send a new request to http://my-project/api/token:
{
"username": "johndoe",
"password": "test"
}
or using curl
curl -X POST http://my-project/api/token -d username=johndoe -d password=test
The MediaServer API returns two fields:
{
"token": "...",
"refresh_token": "..."
}
For authorization, you must to send header for any request: Authorization: Bearer your_token.
Use
The MediaServer API can create(load, crop...) and remove images.
curl -X POST http://my-project/api/images ... - to create
curl -X DELETE http://my-project/api/images/id ... - to delete by id
Simple loading
For create a new image, you can send a new post request with parameter imageFile:
curl -X POST -H "Authorization: Bearer your_token" -H "Content-Type: multipart/form-data" -F "imageFile=@/path/for/your/file.jpg" http://my-project/api/images
The MediaServer API returns one field with the path to the source image:
{
"origin": "http://my-project/uploads/images/5ab/1e4/f82/5ab1e4f821d62240251619.jpg"
}
Create preview
You can create a different preview for image using LiipImagineBundle. In the api, the previews parameter is an array consisting of LiipImagineBundle
filter configurations.
{
"previews": {
"small": {
"thumbnail": {
"size": [50, 50]
}
},
"large": {
"thumbnail": {
"size": [50, 50]
},
"background": {
"size": [124, 94],
"position": "center",
"color": "#000000"
}
}
}
}
For example, creating a small preview:
curl -X POST -H "Authorization: Bearer your_token" -H "Content-Type: multipart/form-data" -F "imageFile=@/path/for/your/file.jpg" -F "previews[small][thumbnail][size][0]=100" -F "previews[small][thumbnail][size][]=50" http://my-project/api/images
The MediaServer API returns the path to the source image, as well as a previews collection:
{
"id": 1,
"createdAt": "2018-07-28T18:35:47+03:00",
"updatedAt": "2018-07-28T18:35:47+03:00",
"name": "5ab1ed5b538e9914783874.png",
"size": 536793,
"origin": "http://my-project/uploads/images/5ab/1ed/5b5/5ab1ed5b538e9914783874.jpg",
"previews": {
"small": "http://my-project/media/cache/view1/rc/qcJ6p4ur/uploads/images/5ab/1ed/5b5/5ab1ed5b538e9914783874.jpg"
}
}
Download simple file
For create a new document, you can send a new post request with parameter documentFile:
curl -X POST -H "Authorization: Bearer your_token" -H "Content-Type: multipart/form-data" -F "documentFile=@/path/for/your/file.jpg" http://my-project/api/documents
The MediaServer API returns the path to the source document:
{
"id": 1,
"createdAt": "2018-07-28T18:35:47+03:00",
"updatedAt": "2018-07-28T18:35:47+03:00",
"name": "5b5c8d539fd93267715216.png",
"size": 536793,
"path": "http://media-server/uploads/documents/5b5/c8d/539/5b5c8d539fd93267715216.png"
}
What's inside
It's the symfony 4 skeleton with the following bundles:
- ext-iconv
- gesdinet/jwt-refresh-token-bundle
- gfreeau/get-jwt-bundle
- guzzlehttp/guzzle
- lexik/jwt-authentication-bundle
- liip/imagine-bundle
- nelmio/cors-bundle
- sensio/framework-extra-bundle
- symfony/console
- symfony/flex
- symfony/form
- symfony/framework-bundle,
- symfony/lts
- symfony/maker-bundle
- symfony/orm-pack
- symfony/security-bundle,
- symfony/swiftmailer-bundle
- symfony/twig-bundle
- symfony/validator
- symfony/yaml
- vich/uploader-bundle
Feedback
- Create a new issue
- Ask a question on сайте.
- Send a message to fafnur@yandex.ru
License MIT.