Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download on Ajax Request #295

Open
dev-aes opened this issue Oct 13, 2022 · 2 comments
Open

Download on Ajax Request #295

dev-aes opened this issue Oct 13, 2022 · 2 comments

Comments

@dev-aes
Copy link

dev-aes commented Oct 13, 2022

is there any solution to this problem? I don't see any guides about downloading sheet files thru ajax request ( Axios)

@conlacda
Copy link

I have the same problem.

@conlacda
Copy link

conlacda commented Oct 14, 2022

@dev-aes
You can refer to my code snippet.
Here I save the file to storage_path and then send it to the client.
PHP code

$fastexcel = new FastExcel($collection);
$fastexcel->export(storage_path("temp_file.csv"));
return response()->download(storage_path("temp_file.csv"), "temp_file.csv")->deleteFileAfterSend(true);

Js code

axios({
    url: 'export-csv',
    method: 'post',
    responseType: 'blob',
    data: {},
}).then((response) => {
    let url = window.URL.createObjectURL(new Blob([response.data]));
    let link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', "temp_file.csv");
    document.body.appendChild(link);
    link.click();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants