2

In the Silverstripe 4 docs the possiblity to use a BLOB or s3 storage is mentioned (https://www.silverstripe.org/learn/lessons/v4/working-with-files-and-images-1)

But I cannot find any documention how to handle a BLOB storage. Is this only about configuration or is some implementation required? Are there examples?

scrowler
  • 24,273
  • 9
  • 60
  • 92
nblum
  • 155
  • 1
  • 1
  • 6
  • SS4 uses the [PHPLeague's flysystem](http://flysystem.thephpleague.com/docs/) package under the hood - in theory you'd need to configure that to store the file contents in a DB blob field. It may require some custom code – scrowler Nov 15 '18 at 09:48
  • that's what I'm looking for. I hoped for some docs or examples. But maybe i have to do it on my own – nblum Nov 19 '18 at 06:14
  • I tried to extend the Public and Protected Adapter ( SilverStripe\Assets\Flysystem\PublicAdapter) but it seems to have no effect in the admin asset manager – nblum Nov 19 '18 at 07:02

1 Answers1

0

You can create a custom DBField class for BLOB.

Here is the example DBBlobField class works in SS 4.2 with MariaDB.

use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBField;

class DBBlobField extends DBField
{
    function requireField()
    {
        DB::require_field($this->tableName, $this->name, "mediumblob");
    }
}

mediumblob is the BLOB type supported by your database.

Define the $db field in DataObject.

private static $db = [
    "Data" => DBBlobField::class
];

Save file content into Data field.

$dataObject->Data = file_get_contents($filePath);
$dataObject->write();
Jasonz
  • 106
  • 5
  • 1
    This may be a proper solution for a special data record but does not work for the hole application and the asset manager – nblum Nov 19 '18 at 06:12