Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                form(action="/models", method="POST", enctype="multipart/form-data", class="signUpForm")
  .field
    .file.has-name.is-boxed
      label.file-label
          input.file-input(type="file", name="headshots", multiple, accept="image/png, image/jpeg")
          span.file-cta
            span.file-icon
              i.fas.fa-upload
            span.file-label Upload Headshots
          span.file-name 5 Maximum

  .field
    .file.has-name.is-boxed
      label.file-label
        input.file-input(type="file", name="bodyshots", multiple)
        span.file-cta
          span.file-icon
            i.fas.fa-upload
          span.file-label Upload Full Bodyshots
        span.file-name 5 Maximum
              
            
!

CSS

              
                
              
            
!

JS

              
                //.env - Holds your secret keys
AIRTABLE_BASE_ID=
AIRTABLE_API_KEY=

CLOUDINARY_URL=

// index.js - Our routes
router.post('/models',
  modelController.upload,
  modelController.resize,
  modelController.createModel);


// modelController.js 
var multer = require('multer');
var cloudinary = require('cloudinary').v2;
var Airtable = require('airtable');

var multerOptions = {
  storage: multer.memoryStorage(),
  fileFilter(req, file, next) {
    const isPhoto = file.mimetype.startsWith('image/');
    if(isPhoto) {
      next(null, true);
    } else {
      next({ message: "That filetype isn't allowed"}, false);
    }
  }
};


var base = new Airtable({
  apiKey: process.env.AIRTABLE_API_KEY,
}).base(process.env.AIRTABLE_BASE_ID);
var tableName = 'Models';
var viewName = 'Grid view';

exports.getModels = (req, res, next) => {
  const page = req.params.page || 1;
  const limit = 25;
  const offset = (page * limit) - limit;

  base('Models').select({
      view: 'Grid view',
      pageSize: limit
  }).eachPage(function page(records, fetchNextPage) {
    fetchNextPage();
  }, function done(err) {
    if(err) { console.error(err); return; }

  });
}

exports.getModel = (req, res) => {
  base('Models').find(req.params.id, function(err, record) {
    if (err) { console.error(err); return; }
    var model = record.fields;
    res.render('model', {title: 'Model', model});
  });
}


exports.upload = multer(multerOptions).fields([{name:'headshots', maxCount: 5}, {name:'bodyshots', maxCount: 5}]);

exports.resize = (req, res, next) => {
  if(!req.files) {
    next();
    return;
  }

  const fileObjects = req.files;

  // Helper function
  function uploadToCloudinary(image) {
    return new Promise((resolve, reject) => {
      cloudinary.uploader.upload_stream(
        {
          resource_type: 'image',
          width: 800,
          crop: 'scale',
          quality: 80
        },
        function(error, result){
          console.log(result.url, error);
          if(error) {
            reject(error);
          } else {
            resolve({"url":result.url});
          }
        }
      ).end(image.buffer);
    })

  }

  let counter = 0;
  for (const fieldname in fileObjects) {
    const images = fileObjects[fieldname];
    let promises = images.map((image) => {
      return uploadToCloudinary(image);
    });

    Promise.all(promises)
      .then(res => {
        counter = counter + 1;
        req.body[fieldname] = res;
        if(counter == 2) {
          next(); // This then calls the createModel after all promises of the for loop are resolved
        }
      })
      .catch(err => {
        console.log(err);
      })

  }

}


exports.createModel = (req, res) => {
  let skills = [];

  if(typeof req.body.skills === 'string') {
    skills.push(req.body.skills);
    req.body.skills = skills;
  }

  base('Models').create({
    "Full Name": req.body.fullname,
    "Parent/Guardian Full Name": req.body.parent,
    "Birth Date": req.body.birthdate,
    "Gender": req.body.gender,
    "Primary Contact": req.body["phone-number"],
    "Email Address": req.body.email,
    "Skills": skills,
    "Ethnicity": req.body.ethnicity,
    "Headshot": req.body.headshots,
    "Full Body Shot": req.body.bodyshots
  }, function(err, record) {
      if (err) { console.error(err); return; }
      console.log(record.getId());
      res.redirect(`/model/${record.getId()}`);
  });

}
              
            
!
999px

Console