Hello, Is there any option to export collection list to external file?
Built this yesterday:
import { stringify } from 'csv-stringify/sync'
import archiver from 'archiver'
export const downloadEndpoint: Endpoint = {
path: '/download-zip',
method: 'get',
async handler(req, res, next) {
// Only admins allowed
if (!isAdmin(req.user)) return next()
const result = await req.payload.find({
collection: 'widgets',
where, // derived from query params
limit: 1000, // sanity check
})
const archive = archiver('zip', { zlib: { level: 9 } })
archive.pipe(res)
res.setHeader('Content-Type', 'application/zip')
res.setHeader('Content-Disposition', 'attachment; filename=widgets.zip')
const csv = stringify(result.docs, { header: true })
archive.append(csv, { name: 'test.csv' })
archive.finalize()
},
}
Thanks for answer! 💚 ,
Do you have some extra configuration for archiver? When I'm trying use it, I have a lot of errors
If it's a webpack error, you should add archiver to payloadconfig.admin.webpack.resolve.alias so ot doesn't try to bundle it. Otherwise not other config
You could consider to skip the zipping and return the csv straight away
thank you so much! Im going to try it
How do i implement this @kosmo @thgh
I've been trying to figure it out
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.