Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adminjs/upload: cannot access uploaded file in action #1710

Open
eugene-ferra opened this issue Sep 19, 2024 · 0 comments
Open

adminjs/upload: cannot access uploaded file in action #1710

eugene-ferra opened this issue Sep 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@eugene-ferra
Copy link

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 eugene-ferra added the bug Something isn't working label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant