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

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

Open
AlexanderBich opened this issue Sep 29, 2021 · 1 comment

Comments

@AlexanderBich
Copy link

AlexanderBich commented Sep 29, 2021

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
Copy link

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[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants