GrahamCampbell / Laravel-Flysystem

A Flysystem bridge for Laravel
https://gjcampbell.co.uk
MIT License
483 stars 88 forks source link

DigitalOcean Spaces #100

Closed timgavin closed 7 years ago

timgavin commented 7 years ago

Any plans for supporting DigitalOcean's Object Storage?

GrahamCampbell commented 7 years ago

If there's a flysystem connector implemented, then sure. :)

robjbrain commented 7 years ago

It looks like this will be problematic because digital ocean spaces requires V2 of pre-signed URL signature and the AWS client and all the flystem stuff only supports V4 and the two are not compatible. Trying to use older versions of flystem isn't possible because it requires an outdated version of the aws sdk php. You could require the outdated versions in composer, however this would stop the other drivers from working (you couldn't have both digital ocean spaces and aws s3 for instance).

I've spent a few hours on this with no luck unfortunately, but that info might help anyone else looking to use digital ocean spaces.

SimplyCorey commented 7 years ago

I'm facing the same issue. I tried to install league/flysystem-aws-s3-v2 but I also wasnt able to get it working correctly.

SimplyCorey commented 7 years ago

Here is some example code for anyone who wants to use V2 signing:

    public function downloadUrl($minutes = 10)
    {
        $expires = Carbon::now()->addMinutes($minutes);
        $config = config('filesystems.disks')[config('filesystems.default')];
        $uri = $this->filename;

        $signature = $this->generateSignature($config, $expires, $uri);

        return "{$config['endpoint']}/{$config['bucket']}/{$uri}?AWSAccessKeyId={$config['key']}&Expires={$expires->timestamp}&Signature={$signature}";
    }

    /**
     * Signs a request.
     *
     * @param $config
     * @param $expires
     * @param $uri
     * @return string
     */
    protected function generateSignature($config, $expires, $uri)
    {
        $request = "GET\n\n\n{$expires->timestamp}\n/{$config['bucket']}/{$uri}";

        return urlencode(base64_encode(hash_hmac('sha1', $request, $config['secret'], true)));
    }
atymic commented 5 years ago

FYI for anyone interested, DO supports v4 now and thus the normal S3 signing works 😄