Giter Club home page Giter Club logo

Comments (4)

sktt avatar sktt commented on September 24, 2024 1

Wouldn't it make more sense if keystone.Field.Types.File has the option to support multiple files or there's a FileCollection type?

from keystone-storage-adapter-s3.

programmer4web avatar programmer4web commented on September 24, 2024 1

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.'); } );   

from keystone-storage-adapter-s3.

josh-hardman avatar josh-hardman commented on September 24, 2024

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!

from keystone-storage-adapter-s3.

askdesigners avatar askdesigners commented on September 24, 2024

That's a decent workaround ^^ 👍

from keystone-storage-adapter-s3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.