Is there a way to use location instead of saving file content when working with Asset\Image?

Viewed 112

Im struggling with Asset\Image. Is there a way to prevent given image from saving on disc and read from given location instead?

Currently Im creating Image like so

        $asset = new Asset\Image();
        $asset->setFilename($location);
        $asset->setData(file_get_contents($location));
        $asset->setParent(Asset::getByPath("/"));
        $asset->save();

And obviously it gets saved on in the public/var folder. Unfortunatelly I cannot afford to do so, because there is like hundreds of GBs of photos.

Is there a way to use location to save and later read image content from saved location?

2 Answers

I think this is not possible by php. You can achive your goal by saving all assets in another location and than replace the public/var folder with a symlink

mkdir /your/asset/storage
cp public/var/assets /your/asset/storage

Danger zone starts here, be sure to have a good backup of all assets

rm -r public/var/assets
ln -s /your/asset/storage public/var/assets

This is only an example and might differ on your system

What was your idea to save disk space? The file takes space anyway, on the disk directly or on the disk managed by Pimcore.

If you have hundreds Gb then check please if those images are Assets or their versions (created on each save). If they are versions then you have options:

  1. limit versions amount/time (see System Settings -> Assets) or in pimcore/system.yml
pimcore:
    assets:
        versions:
            days: null
            steps: 3
  1. disable versioning before to save
Version::disable();
$asset->save();
Version::enable();

And remember that one day you can grow big and need more then 1 fileserver. Pimcore Assets can already manage that, but how will you synchronise assets files?

Related