2017 © Pedro Peláez
 

project 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.

image

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.

  • Saturday, July 28, 2018
  • by Fafnur
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MediaServer

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)., (*1)

Russian documentation here., (*2)

Setup

The MediaServer is a symfony/skeleton application with packages for uploading and cropping images. Some bundles:, (*3)

Installation

Run the Composer command to create a new project, (*4)

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., (*5)

Next step, run command to update database., (*6)

php bin/console d:s:u --force

In MediaServer, authorization was developed using JWT. You can see documentation here., (*7)

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:, (*8)

{
  "username": "johndoe",
  "password": "test",
  "email": "johndoe@example.com"
}

or using curl, (*9)

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:, (*10)

{
  "username": "johndoe",
  "password": "test"
}

or using curl, (*11)

curl -X POST http://my-project/api/token -d username=johndoe -d password=test

The MediaServer API returns two fields:, (*12)

{
  "token": "...",
  "refresh_token": "..."
}

For authorization, you must to send header for any request: Authorization: Bearer your_token., (*13)

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, (*14)

Simple loading

For create a new image, you can send a new post request with parameter imageFile:, (*15)

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:, (*16)

{
  "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., (*17)

{
  "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:, (*18)

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:, (*19)

{
  "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:, (*20)

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:, (*21)

{
    "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"
}

, (*22)

What's inside

, (*23)

It's the symfony 4 skeleton with the following bundles:, (*24)

  • 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., (*25)

The Versions