adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

adminjs/upload: cannot access uploaded file in action

Open eugene-ferra opened this issue 1 year ago • 0 comments

Contact Details

No response

What happened?

I'm trying to implement something like custom validation in my new action (when creating new record). So, at least I want my upload image field to be required. And in future - maybe I'll add some other logic related to this image... So, I need this stuff in my action. I tried to retrieve this uploaded image from request's payload, but I simply haven't got this field.
My schema look like:

model Product {
  id Int @id @default(autoincrement()) 
  title String
  coverImageUrl String
  coverImageMimeType String
  ...other fields
}

My upload feature setup is:

uploadFileFeature({
      componentLoader,
      provider: new MinioProvider('products', {
        baseUrl: '',
      }),
      validation: {
        mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
        maxSize: 2 * 1024 * 1024,
      },
      properties: {
        file: 'image',
        key: 'coverImageUrl ',
        mimeType: 'coverImageMimeType ',
      },
    }),

I wrote my custom MinioProvider, but it doesn't matter. So, this setup give me properly renrered UI, I can uplaod file, I can save all data to db and I can save my image to minio storage. But, as I discovered later, it doesn't provide me my currently uploaded file in the request.payload. Btw, I inspected the request, that was made by adminjs, and my file was successfully included to it under "image.0" property, but this property does not appear in payload.

And, I played a little with this stuff, and discovered next BUG. If I change file: 'image', to any random value like file: 'test',, this action automaticly restarts my backend server, but not restart the frontend. So, changes applies on backend, frontend stays the same. and if I send the same request again (with all the data in form, like it was before this change) then I surprisingly CAN ACCESS to my file via 'image.0' property in payload. So, it is possible in this specific case, in case of this bug. But, when I update the frontend page, and try to create my product again, than problems returns. So, client sends file under new "test.0" property in formData, and I really cant access it.

Maybe someone has any ideas how it is? or maybe I doing something wrong? Is it possible to actually retrieve file data in request paylaod?

Bug prevalence

every time

AdminJS dependencies version

@adminjs/express": "^6.1.0", "@adminjs/prisma": "^5.0.2", "@adminjs/upload": "^4.0.2", "adminjs": "^7.8.12",

What browsers do you see the problem on?

No response

Relevant log output

No response

Relevant code that's giving you issues

No response

eugene-ferra avatar Sep 19 '24 18:09 eugene-ferra