Skip to content

Instantly share code, notes, and snippets.

@TimMikeladze
Created April 18, 2023 16:32
Show Gist options
  • Save TimMikeladze/b93055dae1f8626b3b21c61490648238 to your computer and use it in GitHub Desktop.
Save TimMikeladze/b93055dae1f8626b3b21c61490648238 to your computer and use it in GitHub Desktop.
```ts
import AdmZip from 'adm-zip';
import { NextApiRequest, NextApiResponse } from 'next';
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const zip = new AdmZip();
zip.addFile(
`db.sql`,
Buffer.from(`${yourSQLData}`, `utf8`),
``,
);
res.setHeader(`Content-Type`, `application/zip`);
res.setHeader(`Content-Disposition`, `attachment; filename=export.zip`);
res.send(zip.toBuffer());
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment