0

I am working with an s3 bucket in laravel (11) and have following function in my controller to dowload a given file to chrome:

public function downloadFile(Materials $material) 
   {

        Gate::authorize('view', $material);
        $fileInfo = pathinfo($material->filename);
        $filename = urlencode($material->name) . "." . $fileInfo['extension'];
        return Storage::disk('s3')->response( $material->filename, $filename );
    }

The problem is, that the file does not have the filename in $filename after the download. It is the hash from s3.

But the header seems ok?

Content-Disposition:
inline; filename="DatenschutzerklC3A4rung+Muster.docx"; filename*=utf-8''Datenschutzerkl%25C3%25A4rung%2BMuster.docx

What I also tried so far is:

# number 1
return Storage::disk('s3')->response(
        $material->filename,
        urldecode($filename),
        ['Content-Disposition' => 'attachment']
    );
# number 2
return Storage::disk('s3')->response(
    $material->filename,
    $filename,
    ['Content-Disposition' => "attachment; filename=\"$filename\"; filename*=UTF-8''$filename"]
);

But no Luck ... did I get something wrong?

1 Answer 1

2

If you just want to stream the file as a download to the browser, you could try the following:

return response()->streamDownload(function () {
    echo Storage::disk('s3')->get($filename);
}, $material->filename);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.