4 months ago

Force S3 file download

Posted 4 months ago by Conixs

I'm trying to force a file storaged in S3 to be downloaded by the user. However, in postman it shows the content of the file as base64

$arquivo = Arquivo::find($id);
$assetPath  = Storage::disk('s3')->url($arquivo->des_caminho);
$mimetype   = Storage::disk('s3')->mimeType($arquivo->des_caminho);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . basename($arquivo->nom_arquivo));
header("Content-Type: " . $mimetype);

return readfile($assetPath);

I tried to use return Storage::download($assetPath, basename($arquivo->nom_arquivo), $headers); without success.

Please sign in or create an account to participate in this conversation.