Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sokil/filestoragebundle
Write files to external file system and store metadata to database
https://github.com/sokil/filestoragebundle
filesystem gaufrette symfony symfony-bundle upload
Last synced: 23 days ago
JSON representation
Write files to external file system and store metadata to database
- Host: GitHub
- URL: https://github.com/sokil/filestoragebundle
- Owner: sokil
- Created: 2016-01-05T07:00:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-20T06:33:31.000Z (almost 7 years ago)
- Last Synced: 2024-07-08T07:45:51.357Z (4 months ago)
- Topics: filesystem, gaufrette, symfony, symfony-bundle, upload
- Language: PHP
- Homepage:
- Size: 63.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FileStorageBundle
Working with different filesystems, managing file metadata in Doctrine ORM. Storing metadata allows to prevent loading same file twice by checking file hash.
[![Build Status](https://travis-ci.org/sokil/FileStorageBundle.svg?branch=master)](https://travis-ci.org/sokil/FileStorageBundle)
## Installation
Add composer dependency:
```
composer require sokil/file-storage-bundle
```Add bundle to AppKernel:
```php
## Configuration
* Read about Gaufrette at https://github.com/KnpLabs/Gaufrette.
* Read abount configuring Gaufrette filesystems in Symfony at https://github.com/KnpLabs/KnpGaufretteBundle.### Configuration of supported filesystems
This bundle uses gaufrette as filesystem abstraction, so you need to configure filesystem in app config:
```yaml
knp_gaufrette:
adapters:
acme.attachments_adapter:
local:
directory: "%kernel.root_dir%/attachments"
create: true
filesystems:
acme.attachments_filesystem:
adapter: acme.attachments_adapter
```You need then pass this filesystem name to your code. For example define parameter in extension of your bundle:
```php
setParameter(
$this->getAlias() . '.attachments_filesystem',
$config['attachments_filesystem']
);
}
}
}
```And then in application config:
```yaml
acme:
attachments_filesystem: "acme.attachments_filesystem"
```Now you may use configured filesystems in your controller:
```php
get('knp_gaufrette.filesystem_map')
->get($this->getParameter('acme.attachments_filesystem'));```
## Move local file to filesystem
This bundle usefull for moving local files into some external filesystems and add record to database about file.
First we need to create some file entity. File entity holds useful metadata about stored file.```php
setName('some.txt')
->setSize(4242)
->setCreatedAt(new \DateTime())
->setMime('text/plain')
->setHash('some_hash_of_file_content');
$this
->get('file_storage')
->write(
$file,
'acme.attachments_filesystem',
'some content of file'
);
$fileId = $file->getId(); // now you have id of file
```
## See also
* See how to easy handle uploaded files at https://github.com/sokil/php-upload