Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcgivens21's avatar

Amazon S3 File Download Not Working -- "File not found at path:"

Hello all,

I am having some issues downloading files from Amazon S3. Upload works just fine; however, when I try to download, the file to the S3 file (URL) is missing a slash in the path (showing https:/ instead of https://). Example:

"File not found at path: https:/<PATH HIDDEN FOR PRIVACY>/project_documents/9/14/favicon.png"

Here is my download function in the controller:

public function download(ProjectDocument $project_document)
{

        $s3_file = Storage::cloud()->url($project_document->filepath);
        $mime = Storage::cloud()->getDriver()->getMimetype($s3_file);
        $size = Storage::cloud()->getDriver()->getSize($s3_file);


        $response = [
            'Content-Type' => $mime,
            'Content-Length' => $size,
            'Content-Description' => 'File Transfer',
            'Content-Disposition' => "attachment; filename={$project_document->filename}",
            'Content-Transfer-Encoding' => 'binary',
        ];

        ob_end_clean();

        return response()->download($s3_file, $project_document->filename, $response);
}

Now, even with the weird URL, I can paste that into my browser and see the png file. It is viewable, at least. So I'm not sure what's causing this or why, but man I am having the hardest time downloading files from s3 storage directly to desktop (not locally to server first). Should I be using streamDownload() instead?

In my config\filesystems.php file, I have:

'cloud' => env('FILESYSTEM_CLOUD', 's3'),

and further down in filesystems.php, s3 is defined as:

's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

It should also be noted that I have a working version that copies it to the server temporarily before downloading to the user's machine. THIS WORKS, but I don't want to use the server as the intermediary, if at all possible:

public function download(ProjectDocument $project_document)
    {
        $dlfile = Storage::cloud()->url($project_document->filepath);
        $tempStorage = tempnam(sys_get_temp_dir(), $project_document->filename);
        copy($dlfile, $tempStorage);

        return response()->download($tempStorage, $project_document->filename);
    }  
0 likes
2 replies
TerrePorter's avatar

Very rough, but maybe something like this...

return response()->streamDownload(function ()  use ($s3_file){
    echo file_get_contents(;$s3_file);
},$project_document->filename);```

Please or to participate in this conversation.