SHARE
TWEET

Image Upload - models/ImageUpload.js

christroutner Nov 24th, 2015 (edited) 194 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var keystone = require('keystone');
  2. var Types = keystone.Field.Types;
  3.  
  4. /**
  5.  * Image Upload Model
  6.  * ===========
  7.  * A database model for uploading images to the local file system
  8.  */
  9.  
  10. var ImageUpload = new keystone.List('ImageUpload');
  11.  
  12. ImageUpload.add({
  13.         //name: { type: Types.Key, required: true, index: true }, //requiring name breaks image upload.
  14.         name: { type: Types.Key, index: true},
  15.         image: {
  16.                 type: Types.LocalFile,
  17.                 dest: 'public/uploads/images',
  18.                 label: 'Image',
  19.                 allowedTypes: [ 'image/jpeg', 'image/png', 'image/gif'],
  20.                 filename: function(item, file) {
  21.                         return item.id + '.' + file.extension;
  22.                 }
  23.         },
  24.         alt1: { type: String },
  25.         attributes1: { type: String },
  26.         category: { type: String },      //Used to categorize widgets.
  27.         priorityId: { type: String },    //Used to prioritize display order.
  28.  
  29. });
  30.  
  31.  
  32. ImageUpload.defaultColumns = 'name';
  33. ImageUpload.register();
RAW Paste Data
Top