Downloading private files

September 26, 2018 689 views
Applications Debian 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' => '',

        $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;
        return $response->send();

Thank you very much for your helping.

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=""
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,

Have another answer? Share your knowledge.