Downloading private files

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. Guillaume

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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, Guillaume

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?