Question

I'm using SonataMediaBundle and I don't want to generate icons for certain file types (e.g. pdf, xls, doc). I want to use a default icon (e.g. pdf icon).

I've been reading the Sonata Media documentation, and I believed that I need something like this:

web/uploads/media/media_bundle/images/default_pdf/file.png or web/uploads/media/sonatamedia/files/default_pdf/file.png

neither of which work.

On the chance that <format> meant "small" or "large", I also tried this:

web/uploads/media/media_bundle/images/default_small/file.png

which I assumed would mean that file.png would be shown for every file, regardless of mime-type, if a small icon were required and the file instance didn't have a custom one. I also tried using admin instead of default as the context. No dice.

The icon src is always /uploads/media/sonatamedia/files/admin/file.png- which being an absolute path, does not actually exist.

My icon files are 45px wide, which I have set in config.yml:

        formats:
            small: { width: 45 , quality: 70}
            big:   { width: 500 , quality: 70}
            pdf: { width: 45 , quality: 70} //tried with and without this line

File permissions are 644 and the cache has been cleared. What am I doing wrong?

Was it helpful?

Solution

In the docs, the example config shows:

cdn:
    server:
        path: /uploads/media # http://media.sonata-project.org/

I needed

cdn:
    server:
        path: /ACC/web/uploads/media # http://media.sonata-project.org/

because my site's base url is something like http://example.com/ACC I hope this is useful to others.

OTHER TIPS

Assuming that your document is in the default context

{% thumbnail media, 'big' %}

will give you an image path like this

/uploads/media/sonatamedia/files/default_big/file.png

You just have to copy file.png in /uploads/media/sonatamedia/files/default_big/ and it works.

Edit : Personally I went CSS.

Template :

<a href="{{ path('sonata_media_download', {'id': media|sonata_urlsafeid }) }}"
class="downloadLink">Download {{media.name}}
</a>

CSS :

.downloadLink{
    margin: 10px;
    padding: 10px 10px 10px 62px;
    background: #fff url(../../bundles/mybundle/images/icons/fileIcon.png) left top no-repeat;
    display: block;
    border: 1px solid #ddd;
    height: 60px;
}

Yeah. Its hardcoded in Sonata source like:

// @todo: fix the asset path
$path = sprintf('sonatamedia/files/%s/file.png', $format);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top