ats / resource-bundle
ATS Resource Bundle
v1.0.2
2019-04-12 13:35 UTC
Requires
- php: >=7.0
- alcaeus/mongo-php-adapter: ^1.1
- ats/core-bundle: ^1.0
- doctrine/doctrine-bundle: ^1.9
- doctrine/mongodb-odm: ^1.2
- doctrine/mongodb-odm-bundle: ^3.4
- jms/serializer-bundle: ~2.3
- stof/doctrine-extensions-bundle: ^1.3
- symfony/cache: 3.4.*
- symfony/config: 3.4.*
- symfony/console: 3.4.*
- symfony/dependency-injection: 3.4.*
- symfony/event-dispatcher: 3.4.*
- symfony/filesystem: 3.4.*
- symfony/finder: 3.4.*
- symfony/http-foundation: 3.4.*
- symfony/http-kernel: 3.4.*
- symfony/monolog-bundle: ^3.1.0
- symfony/routing: 3.4.*
- symfony/yaml: 3.4.*
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: 3.0.2
- phpstan/phpstan: ^0.10.3
- phpstan/phpstan-symfony: ^0.10.1
- squizlabs/php_codesniffer: ^3.3
- symfony/browser-kit: 3.4.*
- symfony/debug: 3.4.*
- symfony/dom-crawler: 3.4.*
- symfony/framework-bundle: 3.4.*
- symfony/phpunit-bridge: 3.4.*
- symfony/process: 3.4.*
- symfony/var-dumper: 3.4.*
- symfony/web-server-bundle: 3.4.*
Provides
- ext-mongo: *
This package is not auto-updated.
Last update: 2021-09-19 20:23:06 UTC
README
General
Developer-friendly file upload/download capabilities for Symfony-enabled web applications.
Setup
- Install the bundle in your application
$ php composer require ats/resource-bundle
Register the following parameters :
upload_dir
, which will be the root upload directoryallowed_upload_subdirectories
either as an array of subdirectories (e.g.['foo','bar']
or~
if no subdirectory restrictions are intended)
Register the following bundle in the AppKernel
<?php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // production-enabled bundles... new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new ATS\ResourceBundle\ATSResourceBundle(), ]; } // ... }
- Add routing definition to your
routing.yml
file :resource: resource: "@ATSResourceBundle/Controller/Rest/ResourceController.php" type: "annotation" prefix: "/api"
Configuration
- Include the following YAML nodes in your configuration :
stof_doctrine_extensions:
uploadable:
default_file_path: '%uploads_dir%'
mongodb:
default:
uploadable: true
Usage
The following endpoints are exposed :
- File upload :
POST /api/resource
- Parameters :
file
: should be an uploaded filesubdir
(optional) : provide an upload subdirectory
- Sample output :
{ "id": "5c40598b4e05a91c291641e7", "name": "b4d77cf414cb32ba7c161aa48333fd996a3af15f.srt", "mime_type": "text/plain", "size": "67507" }
- File download :
GET /api/resource/:id
- Parameters :
- Resource ID
- Output : binary content, holding the file MIME type and file name.
- Sample headers :
accept-ranges →bytes cache-control →public connection →close content-disposition →attachment; filename="fbf824d625885a29b24a3e68fe2348c920714752.xlsx" content-length →65481 content-type →application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
FAQ
- My upload directory is publicly accessible from my web server, how can I ensure my resources are only accessible from my API endpoint ? One possible approach is to restrict access as web server level, as illustrated by the following nginx configuration snippet :
location /uploads {
deny all;
return 404;
}
Notice this has no impact on how API endpoints access upload directories, as file fetching is done at filesystem level directly.