Search code examples
phplaravelcloud-storage

saving files to scaleway storage php methode


how to upload an image to scaleway storage by laravel or PHP methods?


Solution

  • Laravel uses FlySystem under the hood to abstract file storage. It provides several drivers out of the box including: S3, Rackspace, FTP etc.

    If you want to support Scaleway, you would need to write a Custom Driver, which you can read more about it here.

    Edit: It seems from the documentation of Scaleway, it supports AWS CLI clients, which means, this should be quite easy to add support for in FlySytem. I tried the following and it worked.

    I added a new driver in config/filesystems.php as follows:

    'scaleway' => [
        'driver' => 's3',
        'key' => '####',
        'secret' => '#####',
        'region' => 'nl-ams',
        'bucket' => 'test-bucket-name',
        'endpoint' => 'https://s3.nl-ams.scw.cloud',
    ]
    

    and then, to use the disk, I did the following:

    \Storage::disk('scaleway')->put('file.txt', 'Contents');
    

    My file was uploaded.

    EDIT: I also made a PR to get Scaleway accepted in the list of adapters for League's FlySystem. It got merged. You can see it live here.