Closed programmer4web closed 6 years ago
Wouldn't it make more sense if keystone.Field.Types.File
has the option to support multiple files or there's a FileCollection
type?
Has there been any follow up or work arounds for this? I really need to upload multiple images to S3 just like I could with the CloudinaryImages type. Any help would be greatly appreciated!
the same way no, but I have used an different model Images and an relationship to that model: one model:
Image.add({
img : { type: Types.File, storage: s3Storage }
});
MyModel.add({
files : { type: Types.Relationship, ref: 'Image', many: true, note: 'Images from Users.' }
});
save route example:
new MyModel(data).save().then( function(mymodel){
MyModel.findById( mymodel._id ).exec().then(function(mymodel){ //get mymodel unpopulated to avoid error
keystone.list('MyModel').updateItem( mymodel, data, { files: req.files }, function(err){ // update the mymodel with files step 1
if(err) return error(err,'Preview save error.');
var ids = [],
saveImage = function iteratee(item, callback) {
new Image({ img: item }).save().then( function(image){
Img.updateItem( image, { img: item }, { files: req.files }, function(err){
if(err) return error(err,'Client Design Image upload error.');
ids.push(image._id);
callback();
});
});
},
success = function(){ // After Images Saved Successfully
// console.log('Ids: ', ids);
mymodel.images = ids;
mymodel.save().then(function(){
// next operation here if any..
});
};
// console.log('Type: ', typeof(imgs));
switch( typeof(imgs) ){
case 'string': saveImage( imgs, success ); break;
case 'object': async.eachSeries(imgs, saveImage, success); break;
default:
mymodel.populate('ingredient container', function(err,mymodel){
//next operation here if any
});
}
}, function(err){ if(err) return error(err, 'MyModel update error.'); } );
}, function(err){ if(err) return error(err, 'MyModel find error.'); } );
}, function(err){ if(err) return error(err, 'MyModel save error.'); } );
That's a decent workaround ^^ 👍
not an issue but can this be used or extended for Multiple Images? for front-end I use:
on model:
then on server side: