Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @type {AdminBro.After<AdminBro.ActionResponse>} */
- const after = async (response, request, context) => {
- const { record, uploadImage } = context;
- // If the record exists, update it with the uploaded image
- if (record && record.isValid() && uploadImage) {
- await record.update({ image: uploadImage });
- }
- return response;
- };
- /** @type {AdminBro.Before} */
- const before = async (request, context) => {
- if (request.method === 'post') {
- const { uploadImages, uploadImage, ...otherParams } = request.payload;
- if (uploadImage) {
- const base64Image = fs.readFileSync(uploadImage.path).toString('base64');
- otherParams.image = base64Image; // add the image data to the payload
- }
- return {
- ...request,
- payload: otherParams,
- };
- }
- return request;
- };
Add Comment
Please, Sign In to add comment