keystone-classic icon indicating copy to clipboard operation
keystone-classic copied to clipboard

Cloudinary: multiple images upload not working

Open asaptf opened this issue 6 years ago • 16 comments

In some reason, upload of multiple files to Cloudinary not working, if I'm trying to upload more than two files. Just one (random) picture being uploaded.

The model is very simple:

const keystone = require('keystone');
const Types = keystone.Field.Types;

const Gallery = new keystone.List('Gallery', {
	autokey: { from: 'name', path: 'key', unique: true },
});

Gallery.add({
	name: { type: String, required: true },
	publishedDate: { type: Date, default: Date.now },
	image: { type: Types.CloudinaryImages, autoCleanup : true }
});

Gallery.register();

Each image i'm trying to upload is not bigger than ~500KB

Thanks

asaptf avatar Nov 20 '18 09:11 asaptf

same by me. only one image uploaded.

milanffm avatar Dec 07 '18 11:12 milanffm

The problem is also by the keystone Demo: http://demo.keystonejs.com/keystone/galleries if you upload many images, only one of them will be safed. I tried it with: Firefox, Chrome on Mac and Windows!

milanffm avatar Jan 07 '19 15:01 milanffm

@asaptf and @milanffm, have you tried this with the latest version of Keystone?

autoboxer avatar Apr 10 '19 14:04 autoboxer

yeah with 4.0.

milanffm avatar Apr 10 '19 15:04 milanffm

I face this issue too.

abhijithvijayan avatar May 04 '19 04:05 abhijithvijayan

This worked in a previous version and I find it not working anymore. One application in production is still running 4.0.0-rc.0 which it doesn't work in and moving to 4.1.1 it remains broken. We moved to 4.0.0-rc.0 some time ago because it resolved some issues, unaware of breaking this feature. Edit: Actually, double checking it does work when I set Keystone version to 4.0.0-rc.0 and rc.1 but not 4.0.0 or higher.

1337cookie avatar Jul 06 '19 08:07 1337cookie

Issues hasn't been fixed yet. Version 4.1.1

maksym-lukianenko avatar Jul 12 '19 16:07 maksym-lukianenko

this only works in version: 4.0.0-beta.8

milanffm avatar Jul 19 '19 07:07 milanffm

Does anybody know how to fix this issue? Unfortunately downgrade will cause another issues, which have been fixed already 😅

maksym-lukianenko avatar Jul 19 '19 07:07 maksym-lukianenko

this only works in version: 4.0.0-beta.8

Have you tried rc.0 and rc.1? I rolled back some versions and then forward again. And it started working so it might be something to do with an npm dependency, perhaps with a non-specific version. I'm not sure how to debug it without it upgrading all the packages down the line automatically.

Edit: I've just realised it works with 1 or 2 images but any more and it only uploads 1.

1337cookie avatar Jul 19 '19 08:07 1337cookie

Hi guys,

Had a look in the type definition file : CloudinaryImagesType. Looks like the _.flatten() function isn't working well and the array given to the async.map (which will upload the files to cloudinary) isn't really flattened (Only on depth level one)

The workaround was to write a flattening function instead of using the lodash one (which works only on one depth level).

Here the function in the file 'keystone\fields\types\cloudinaryimages\CloudinaryImagesType.js' :

const flatten = arr => arr.reduce( (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [] ); values = flatten(values)

Instead of :

values = _.flatten(values);

reztin avatar Jul 21 '19 18:07 reztin

@Niiitzer thanks a lot, mate! This works awesome!

maksym-lukianenko avatar Aug 06 '19 11:08 maksym-lukianenko

@Niiitzer thanks man, that was the fix for this :-) yeah

milanffm avatar Aug 16 '19 12:08 milanffm

Did someone make a PR for this?

abhijithvijayan avatar Aug 17 '19 03:08 abhijithvijayan

Did someone make a PR for this?

There's currently a monolithic PR ( https://github.com/keystonejs/keystone/pull/4774 ) that has been looming around for some time that likely addresses this too. It's too big to merge as one PR so it's waiting for someone to split it up into multiple PR so changes and issues can be tracked better. Currently keystone is "stable" even though sometimes buggy it doesn't break so keeping PRs manageable is a priority.

1337cookie avatar Aug 21 '19 00:08 1337cookie

Thanks! @Niiitzer I got it working finally!

j3ang avatar Feb 04 '20 05:02 j3ang