Save assets (images, pdf,..) to database (MySQL, MariaDB)

Hi everyone,
I’ve been looking through the documentation and I can’t find any examples on how to store images and documents into the database. By default these are stored in the Upload folder. I know the main concern is the database bloat, but this is not a problem for my project. Is there a simple way to set this up?
BR, Bagus

I don’t know of any way to do this out of the box, so you’ll pretty much need to roll it yourself.

There is a PDO adaptor for flysystem, so you may be able to connect that to the assets classes and do something there. Alternatively if you only want some of the files in the database, you might need to manually create the binary data and store it / retrieve it with some custom methods.

I’m interested in the use-case, what’s the advantage for you in having the files stored in the DB?

I was kinda hoping that this would be a simple task :slightly_smiling_face:
My app will be behind a load balancer (multiple instances + backup). I tested this and it works as desired. The only problem are the images and .pdf files that get uploaded only to a single instance. There won’t be a lot of images so the bloat is not really a problem.
Another option would be rsync but I do need both solutions working.

You could possibly just use a common file system such as AWS S3 to store your files instead. There’s a connector for that which should drop straight in: GitHub - silverstripe/silverstripe-s3: SilverStripe module to store assets in S3 rather than on the local filesystem (SS4 only)

That way your filesystem sits outside the realm of your web instances, and can be delivered directly, via CDN, etc. if you wish.

I was looking into that, but the requirement is to have all assests “inhouse”. So no cloud solution…

If your IT is in house, can you just get an NFS volume attached to the web instances? Same idea, just different technology

For now we agreed that we’ll synchronize images and documents with rsync :slight_smile: