Hi,
I am trying to create a thumbnail after uploading a PDF file.
So I have two fields.
` {
name: "file",
type: "upload",
relationTo: "media",
label: "File (PDF only)",
required: true,
filterOptions: {
mimeType: { contains: "pdf" },
},
admin: {
description:
"Filename should have a readable and understandable name such as BPRO-Speisenverteilung.pdf – Avoid abreviations and filenames that users don’t comprehend.",
},
},
{
name: "thumbnailImage",
type: "upload",
relationTo: "media",
label: "Thumbnail image",
required: true,
admin: {
description: "Recommended size: 144x204px",
},
},`
I would like to use a library such as https://www.npmjs.com/package/pdf-thumbnails-generator to generate the thumbnail.
My idea is to leverage the beforeValidate hook to call this library with the PDF uploaded in the file field. Once I have the base64 image, I can use the localApi to upload the thumbnail to my media collection https://payloadcms.com/docs/upload/overview#uploading-files / https://stackoverflow.com/a/68671469/6318229
However, I don't know what to return in the hook so the thumbnail image field gets automatically populated based on the result of the localAPI create method.
If anyone has a better approach to do, I would love to hear your ideas.
Library to generate thumbnails from given pdf. Latest version: 1.0.6, last published: 3 years ago. Start using pdf-thumbnails-generator in your project by running npm i pdf-thumbnails-generator. There are no other projects in the npm registry using pdf-thumbnails-generator.
I'm currently working on a Node.js middleware and I need to send a file to an API using a formdata.
I've managed to do this when I use a file on my local storage using fs to create a ReadStream an...