Comments (11)
indeed i think we miss a cmf media FileType that would look very similar (and probably can share code with) ImageType. do you want to have a look at what we do for the image and try to generalize that to handle plain files?
we already have the FileController with downloadAction - i guess that should have a viewAction that omits the Content-Disposition so the file can be viewed in a browser directly (again without duplicating all the code there)
for the file extensions, that would be a general symfony question. i found nothing here http://symfony.com/doc/current/reference/forms/types/file.html
this is a whole can of worms, as you have both the mime type and the extension to worry about, and in general can not trust the client to respect things. but i propose you discuss that in the core symfony channels as its not related specifically to the cmf.
@rmsint do you have inputs for nicolas?
from media-bundle.
Ok David thanks for your answer.
So just to be sure, the first line of the mediabundle doc say :
Media can be images, binary documents (like pdf files), embedded movies, uploaded movies, MP3s, etc.
So you confirm than right now only images works ?
Did somebody already try to use SonataMedia with the CMF ?
Thanks a lot
from media-bundle.
Hey Nicolas,
Underneath some inputs from my side, hope it helps you further. (It is some time ago I worked with Symfony, so my knowledge may be a bit rusty.)
Form Type
For a file upload you can use the symfony file
form type. After that persist it to phpcr using the Symfony\Cmf\Bundle\MediaBundle\File\UploadFileHelperDoctrine:handleUploadedFile
. See the webtest/demo app for an example: https://github.com/symfony-cmf/MediaBundle/blob/master/Tests/Resources/Controller/PhpcrFileTestController.php#L58
Of course you can make it easier, fe. to use with sonata admin, by creating a form type cmf_media_file
that puts the last step in a transformer. Actually, the transformer Symfony\Cmf\Bundle\MediaBundle\Form\DataTransformer\ModelToFileTransformer
is already handling files and images, so it is just a matter of creating the form type. You can also control then how an uploaded file is rendered, fe. you maybe want to display the filename and filesize and/or a thumnail for your pdf. If it is that generic, and more people can benefit, you could do a PR?
Here a the steps and links how this is done for the cmf_media_image
:
- the
cmf_media_image
form type extends the Symfony file type, see https://github.com/symfony-cmf/MediaBundle/blob/master/Form/Type/ImageType.php#L42- the
ModelToFileTransformer
is configured in thebuildForm
method, it helps you to persist to phpcr. It accepts - notice some configuration params, about imagine, being forwarded to the template
- the
- the
ModelToFileTransformer
createa a FileInterface object, PR #82 adds to also use theSymfony\Cmf\Bundle\MediaBundle\File\UploadFileHelperDoctrine:handleUploadedFile
here - a custom twig widget does some image rendering, see https://github.com/symfony-cmf/MediaBundle/blob/master/Resources/views/Form/fields.html.twig
- in this widget an imagine filter is being used, however you can also use fe. a download url in your widget. You can then use the twig function
cmf_media_download_url
, seeSymfony\Cmf\Bundle\MediaBundle\Twig\Extension\CmfMediaExtension
andSymfony\Cmf\Bundle\MediaBundle\Templating\Helper\CmfMediaHelper
- in this widget an imagine filter is being used, however you can also use fe. a download url in your widget. You can then use the twig function
See also https://github.com/symfony-cmf/symfony-cmf/wiki/Media, it describes some ideas we had before writing this bundle. If I remember correctly there has been some discussion about a PDF having a preview image, there should be a note about this.
File extensions
If the file extensions are important to your application you can add some guards to your model. Fe. a PDF file that only accepts the pdf
extension. You could use the symfony validation and/or add guards directly in the model for the content setters. Whatever suits your app best I would say. Symfony has already some code to map between mime-types and extensions, see https://github.com/symfony/HttpFoundation/blob/master/File/UploadedFile.php#L173.
from media-bundle.
thanks a lot for the inputs roel.
regarding mime-types, see also #77
from media-bundle.
@nicolas-bastien, for me: yes and no. No with the CmfMediaBundle. Yes, before this bundle existed I had an integration working with SonataMedia and the CMF. I think now 70% of the work is done for integrating with SonataMedia. The Gaufrette adapter is created to do the heavy lifting of the integration with SonataMediaBundle. I expect most work needs to be done in the SonataMediaBundle, and maybe some bugfixes in the CmfMediaBundle.
from media-bundle.
Hi, thanks so much for your answers.
I will do that next week. I need to make it work on my project before the
end of april.
Then I'll help improving the bundle.
Thanks again for your help
Nico
On 16 April 2014 16:12, Roel Sint [email protected] wrote:
@nicolas-bastien https://github.com/nicolas-bastien, for me: yes and
no. No with the CmfMediaBundle. Yes, before this bundle existed I had an
integration working with SonataMedia and the CMF. I think now 70% of the
work is done for integrating with SonataMedia. The Gaufrette adapter is
created to do the heavy lifting of the integration with SonataMediaBundle.
I expect most work needs to be done in the SonataMediaBundle, and maybe
some bugfixes in the CmfMediaBundle.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/99#issuecomment-40603208
.
from media-bundle.
@nicolas-bastien see sonata-project/SonataMediaBundle#509. Another discussion to pickup integration with SonataMediaBundle
from media-bundle.
do we need to do anything on the cmf side?
from media-bundle.
Hi,
So thanks to your help I managed to make a file input field.
One problem is that every time I update my document the file (like the
image) field is deleted.
To correct that I made a custom admin and use a sonata_type_admin.
So my media solution is not really great, I'll come back when something
will be working.
Nico
On 8 May 2014 17:45, David Buchmann [email protected] wrote:
do we need to do anything on the cmf side?
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/99#issuecomment-42566259
.
from media-bundle.
you did see that our models check if the file is being set to null and in that case do not remove the child?
from media-bundle.
ping @nicolas-bastien
from media-bundle.
Related Issues (20)
- use MediaBundle twig functions HOT 1
- Changing Media entity twice in same request is trying to delete directory HOT 5
- Can we use S3DataStore with Jackrabbit implementation for media bundle? HOT 1
- FileController can't handle file name with Chinese character HOT 3
- Symfony 3.x compatibility HOT 2
- Could not load type "cmf_media_image" HOT 2
- unimplemented getParent method HOT 1
- the future of this bundle
- Add new File structure HOT 1
- Hierarchy vs. Hierarchy HOT 1
- Configuration Issue: "There is no extension able to load the configuration for cmf_media" HOT 4
- Integration with Entities: Project Example
- PHP Fatal error Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Directory HOT 1
- Unknown "cmf_media_display_url" function. HOT 2
- ChildrenCollection of medea files fails HOT 1
- Fix SonataMedia integration
- Do not use deprecated method HOT 1
- Automaticially add parent document for collection fresh collection items
- Symfony\Cmf\Bundle\MediaBundle\Adapter\ElFinder\PhpcrDriver::$options must be protected or weaker HOT 4
- Attempted to load class "ElFinderVolumeDriver" from namespace "FM\ElFinderPHP\Driver" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from media-bundle.