novanda1 / payload-imagekit

Send Payload CMS uploads and deletes to ImageKit
https://www.npmjs.com/package/payloadcms-plugin-imagekit
20 stars 3 forks source link

AITags can't be saved #3

Closed zanami closed 1 year ago

zanami commented 1 year ago

I'm trying to use AITags in savedProperties I'm using version 0.2.4 but field handling seems unchanged in 0.2.5 (all fields are text unless it's width, height and some boolean)

ERROR (payload): ValidationError: media validation failed: imagekit.AITags: Cast to string failed for value "[
  { name: 'Sky', confidence: 97.46, source: 'google-auto-tagging' },
  { name: 'Train', confidence: 96.37, source: 'google-auto-tagging' },
  { name: 'Cloud', confidence: 95.96, source: 'google-auto-tagging' }
]" (type Array) at path "AITags"
novanda1 commented 1 year ago

Yep that because we can't save stringified array into MongoDB text.
So instead of save all object we can just save the tags into inline string separated by comma like this:

Nature,Night,Outdoors,Scenery,Sky,Atmosphere,Cloud,World,Mountain,Snow,Natural landscape,Biome,Atmospheric phenomenon,Tree

If you need use that in array, you can split that. tags.split(",")