Question

Downloading private files

Posted September 26, 2018 1.6k views
ApplicationsDebian 9

Good evening, everyone,
Is it possible to obtain a protected url to download files on a private space? I also tried with Flysystem to distribute the files for download, but I can’t, they’re all corrupted.

        $client = new S3Client([
            'credentials' => [
                'key'    => '',
                'secret' => '/pn8IBKqObu7TAM',
            ],
            'region' => '',
            'version' => 'latest',
            'endpoint' => 'https://ams3.digitaloceanspaces.com',
        ]);

        $adapter = new AwsS3Adapter($client, '');

        $filename = 'toto.png';
        $fs = new Filesystem($adapter);
        $downloadable_file_stream = $fs->readStream('sounds/toto.png');
        $downloadable_file_stream_contents = stream_get_contents($downloadable_file_stream);

        $response = new StreamedResponse();
        $response->setCallback(function () use ($downloadable_file_stream_contents) {
            echo $downloadable_file_stream_contents;
            flush();
        });
        return $response->send();

Thank you very much for your helping.
Guillaume

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

If the document is set to private and you are receiving contents that means the connection is open and receiving data, otherwise you would receive an error that the document is unavailable.

So if there is data that is coming sounds like a mismatch perhaps in expected data types?

When I check with text file, I receive contents of my file but with header :

HTTP/1.1 200 OK
Date: Thu, 27 Sep 2018 06:59:35 GMT
Server: Apache/2.4.29 (Ubuntu)
Vary: Authorization,Accept-Encoding
Cache-Control: no-cache, private
Content-Disposition: attachment; filename=toto.png
Link: <http://localhost/api/public/api/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"
Content-Length: 517
Content-Type: text/html; charset=UTF-8

Any ideas to download only the content of file, and for all file type? Or just obtain file private url from my space..
Thank you very much for all,
Guillaume

Submit an Answer