ftm-pm/media-server

This package is abandoned and no longer maintained. No replacement package was suggested.

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.

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:

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

License MIT.