We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
import { AxiosError } from 'axios'; import { NextApiRequest, NextApiResponse } from 'next'; import instance from '@libs/wordpress'; const handler = async (req: NextApiRequest, res: NextApiResponse) => { if (req.method === 'POST') { try { const { data, status } = await instance.post('/download-route', { ids: req.body }); const { data: file } = await instance.get(data.url, { responseType: 'arraybuffer' }); res.setHeader('Content-Type', data.contentType); res.setHeader('Filename', data.basename); return res.status(status).send(file); } catch (e) { const err = e as AxiosError; const status = err?.response?.data?.statusCode || 400; return res.status(status).json({ ...err?.response?.data }); } } else { return res.status(400).json({ message: 'Bad request!' }); } }; export default handler;
The text was updated successfully, but these errors were encountered:
import { useCallback, useState } from 'react'; import axios from 'axios'; import fileDownload from 'js-file-download'; import routes from '@libs/routes'; const useFileDownload = () => { const [downloading, setDownloading] = useState<boolean>(false); const downloadFiles = useCallback( files => { setDownloading(true); axios .post(routes.api.download, files, { responseType: 'blob' }) .then(results => { const file = new Blob([results.data]); fileDownload(file, results.headers.filename); }) .finally(() => setDownloading(false)); }, [setDownloading] ); return { downloading, downloadFiles, }; }; export default useFileDownload;
Sorry, something went wrong.
igorbumba
No branches or pull requests
The text was updated successfully, but these errors were encountered: