How to use the keystone.expandPath function in keystone

To help you get started, we’ve selected a few keystone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VelizarMihaylov / medium-keystone-react-cms / server / models / recipe.js View on Github external
var keystone = require('keystone');
var Types = keystone.Field.Types;

// Create a new Keystone list called Recipe
var Recipe = new keystone.List('Recipe', {
	autokey: { path: 'slug', from: 'name', unique: true },
	defaultSort: '-createdAt',
});

// Adding the option to add an image to our Recipe from
var recipeImgStorage = new keystone.Storage({
	adapter: keystone.Storage.Adapters.FS,
	fs: {
		// required; path where the files should be stored
		path: keystone.expandPath('server/public/img'),
		generateFilename: function (file, index) {
			return file.originalname;
		},
		whenExists: 'error',
		// path where files will be served
		publicPath: '/public/img',
	},
});

// Finally we are gonna add the fields for our Recipe
Recipe.add({
	name: {
		type: String,
		required: true },
	state: {
		type: Types.Select,
github skagitpublishing / connextCMS / models / FileUploads.js View on Github external
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
 * File Upload Model
 * ===========
 * A database model for uploading images to the local file system
 */

var FileUpload = new keystone.List('FileUpload');

var myStorage = new keystone.Storage({
    adapter: keystone.Storage.Adapters.FS,
    fs: {
      path: keystone.expandPath('./public/uploads/files'), // required; path where the files should be stored
      publicPath: '/public/uploads/files', // path where files will be served
      
      //File paths for Docker container.
      //path: keystone.expandPath('../public/uploads/images'), // required; path where the files should be stored
      //publicPath: '../public/uploads/images', // path where files will be served
    }
});

FileUpload.add({
        //name: { type: Types.Key, required: true, index: true }, //requiring name breaks image upload.
	name: { type: Types.Key, index: true},
  file: { 
		//type: Types.LocalFile, 
    type: Types.File,
    storage: myStorage
		//dest: 'public/uploads/files', 
github skagitpublishing / connextCMS / models / ImageUploads.js View on Github external
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
 * Image Upload Model
 * ===========
 * A database model for uploading images to the local file system
 */


var ImageUpload = new keystone.List('ImageUpload');

var myStorage = new keystone.Storage({
    adapter: keystone.Storage.Adapters.FS,
    fs: {
      path: keystone.expandPath('./public/uploads/images'), // required; path where the files should be stored
      publicPath: '/public/uploads/images', // path where files will be served
      
      //File paths for Docker container.
      //path: keystone.expandPath('../public/uploads/images'), // required; path where the files should be stored
      //publicPath: '../public/uploads/images', // path where files will be served
    }
});

ImageUpload.add({
        //name: { type: Types.Key, required: true, index: true }, //requiring name breaks image upload.
	name: { type: Types.Key, index: true},
  image: { 
		//type: Types.LocalFile, 
    type: Types.File,
    storage: myStorage
		//dest: 'public/uploads/images', 
github skagitpublishing / connextCMS / models / exampleFile.js View on Github external
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
 * File Upload Model
 * ===========
 * A database model for uploading images to the local file system
 */

var ExampleFile = new keystone.List('ExampleFile');

var myStorage = new keystone.Storage({
    adapter: keystone.Storage.Adapters.FS,
    fs: {
        path: keystone.expandPath('./uploads'), // required; path where the files should be stored
        publicPath: '/public/uploads', // path where files will be served
    }
});

ExampleFile.add({
        //name: { type: Types.Key, required: true, index: true }, //requiring name breaks image upload.
	name: { type: Types.Key, index: true},
  file: { 
		//type: Types.LocalFile, 
    type: Types.File,
    storage: myStorage
  },
    
});
github keystonejs / keystone-test-project / models / File.js View on Github external
var keystone = require('keystone');
var transform = require('model-transform');
var Types = keystone.Field.Types;

var File = new keystone.List('File');

var storage = new keystone.Storage({
	adapter: keystone.Storage.Adapters.FS,
	fs: {
		path: keystone.expandPath('./uploads'),
		publicPath: '/public/uploads/',
	},
	schema: {
		mimetype: false,
		size: false,
		originalname: true,
	},
});

File.add({
	name: { type: String },
	file: { type: Types.File, storage: storage, required: true, initial: true },
});

transform.toJSON(File);
File.defaultColumns = 'name, file';
github promethe42 / cocorico / api / src / models / Media.js View on Github external
var keystone = require('keystone');
var transform = require('model-transform');
var config = require('/opt/cocorico/api-web/config.json');
var Types = keystone.Field.Types;

var Media = new keystone.List('Media', {
  autokey: { path: 'slug', from: 'title', unique: true },
  map: { name: 'title' },
  track: { createdAt: true, updatedAt: true },
});

var storage = new keystone.Storage({
  adapter: keystone.Storage.Adapters.FS,
  fs: {
    path: keystone.expandPath('../../app/public/'+ config.uploadDir),
    publicPath: '/' + config.uploadDir,
  },
});

Media.add({
  title: { type: String, required: true },
  file: {
    type: Types.File,
    storage: storage,
    allowedTypes: [
      'image/jpeg',
      'image/png',
      'image/svg+xml',
    ],
    filename: function(item, file) {
      return item.slug + '.' + file.extension