Guest User

Untitled

a guest
Mar 15th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. /** @type {AdminBro.After<AdminBro.ActionResponse>} */
  2. const after = async (response, request, context) => {
  3. const { record, uploadImage } = context;
  4. // If the record exists, update it with the uploaded image
  5. if (record && record.isValid() && uploadImage) {
  6. await record.update({ image: uploadImage });
  7. }
  8. return response;
  9. };
  10.  
  11. /** @type {AdminBro.Before} */
  12. const before = async (request, context) => {
  13. if (request.method === 'post') {
  14. const { uploadImages, uploadImage, ...otherParams } = request.payload;
  15. if (uploadImage) {
  16. const base64Image = fs.readFileSync(uploadImage.path).toString('base64');
  17. otherParams.image = base64Image; // add the image data to the payload
  18. }
  19. return {
  20. ...request,
  21. payload: otherParams,
  22. };
  23. }
  24. return request;
  25. };
Add Comment
Please, Sign In to add comment