adminjs-upload icon indicating copy to clipboard operation
adminjs-upload copied to clipboard

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

Open AlexanderBich opened this issue 3 years ago • 1 comments

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

AlexanderBich avatar Sep 29 '21 20:09 AlexanderBich