'HTTP 416 status when trying to download a file via axios
I am using axios to request a file from a Laravel backend like this:
axios({
method: 'post',
url: `/admin/project/export-participants/${project.id}`,
responseType: 'blob',
data: filters
}).then(response => {
const blob = new Blob([response.data]);
saveAs(blob, `${project.title}_participants.xlsx`);
}).catch(error => console.log(error));
Here is the endpoint in Laravel:
public function exportParticipants(Project $project, Request $request): BinaryFileResponse
{
$filters = $request->all();
$users = (new GetFilteredUsersService())->projectParticipants(
$project,
$filters,
$request->get('search'),
$request->get('sort', GetFilteredUsersService::DEFAULT_SORT),
$request->get('dir', GetFilteredUsersService::DEFAULT_SORT_DIR)
);
return (new ProjectUsersExport($project, $users))->download($project->title . '_participants.xlsx');
}
For some reason it works fine locally (using valet) but it doesn't on the production server, which always returns an HTTP 416 error. I don't want to make a range request but it seems the browser somehow forces it (but only in production?).
Are there any server settings that could lead to this? Or is it Laravels fault? I'm lost and would appreciate any help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
