SoftwareBrothers / adminjs-upload

AdminJS Feature - Upload Files
MIT License
18 stars 48 forks source link

BUG: Cannot upload upload files into Postgres TypeORM with multiple: true #33

Open AlexanderBich opened 3 years ago

AlexanderBich commented 3 years ago

Description

When I'm trying to update/create a resource with uploader that has multiple: true option it will not save the photos into the database record

Possible issue source

After some research I found that with multiple: true params are stored in variant: { 'photos.bucketKey.0': 'kjgiqh23pib4h2b34jh234', 'photos.name.0': 'picture.png' }

Meaning 0 is placed at the end, so unflatten creates from it the following object: { photos: { bucketKey: ['kjgiqh23pib4h2b34jh234'], name: 'picture.png' } }

But running update on typeorm repository will throw following error: QueryFailedError: cannot get array length of a non-array

I think it's the case why its not working

Possible solution

Replace the form of multiple files handling into: { 'photos.0.bucketKey': 'kjgiqh23pib4h2b34jh234', 'photos.0.name': 'picture.png' } (zeros are placed in the middle)

Environment

adminjs: 5.2.1 @adminjs/upload: 2.0.1 @adminjs/typeorm: 2.0.0 typeorm: 0.2.36 postgresql: 13.3

skverma618 commented 1 year ago

You should change the datatype of field storing address of images. When you store multiple images, it uploaded in the form of array. So, change the definition of your table and make sure the column store following datatype image_url text[],

If you are using any ORM like prisma to build models, use

image_url String[]