I am using Laravel vapor to host my application, and I am having issue downloading certain file types from AWS S3. I'm wondering if this is a CloundFront issue with the request headers not allowing these file types. Since I am able to download PNG, JPG, PDF files fine, I just have issue with files like DOCX & XLSX. In my API I am just using the Storage facade to stream the download.
/**
* Download file from storage
* @param Document $document
* @return StreamedResponse
*/
public function download(Document $document): StreamedResponse
{
return Storage::disk('s3')->download($document->path);
}
Here are the request header which I believe are set
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
This is the error that is thrown
Was able to resolve by making a temporary link to the item in S3 storage, and redirect away for initialize download.
public function download(Document $document): RedirectResponse
{
$url = Storage::temporaryUrl(
$document->path
now()->addMinutes(30)
);
return Redirect::away($url);
}
Refernce from Vapor Docs: https://docs.vapor.build/1.0/projects/development.html#binary-responses