How to use express-fileupload - 9 common examples

To help you get started, we’ve selected a few express-fileupload 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 simpletut / Universal-React-Apollo-Registration / server.js View on Github external
template: 'passwordReset',
        context: {
            email: req.body.email,
            password: req.body.generatedPassword
        }
    }, function(err, res){
        if(err){
            // console.log(err)
            return response.status(500).send('500 - Internal Server Error')
        }
        response.status(200).send('200 - The request has succeeded.') 
    });

});

app.use(fileUpload());
const getFileType = (fileType) => {
    let ext;
    if(fileType == 'image/jpeg'){
        ext = '.jpg';
    }else if(fileType == 'image/png'){
        ext = '.png';
    }
    return ext;
}

app.post('/upload', function(req, res) {
    
    if (!req.files) return res.status(400).send('No files were uploaded.');

      var current_files = fs.readdirSync('./user-uploads/profile-images/');
      let profilePic = req.files.selectedFile;
github kevoj / nodetomic-api-swagger / src / core / engine.js View on Github external
export default (app) => {

  app.use(bodyParser.json({ limit: '5mb' }));
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(fileUpload());
  app.use(cookieParser());
  app.use(methodOverride());
  app.use(compression());
  app.use(helmet());
  app.use(cors({ origin: true, credentials: true }));

  if ("twitter" in config.oAuth && config.oAuth.twitter.enabled)
    app.use(session({ secret: config.secret, resave: false, saveUninitialized: false }));

  app.use(passport.initialize());
  app.use(passport.session());

  // Liverload
  if (config.livereload.enabled)
    app.use(require('connect-livereload')({ src: `http://${config.livereload.ip}:${config.livereload.port}/livereload.js` }));
github origami-cms / cms / packages / core-server / src / Server.ts View on Github external
private async _setup() {
    // Setup the store
    if (this.store) {
      this.app.set('store', this.store);
    }

    this.app.use(fileUpload());
    this.app.use(
      helmet({
        frameguard: {
          action: 'allow-from',
          domain: '*'
        }
      })
    );
    this.app.use(corser.create());

    await this._setupStatic();

    // Setup the middleware
    await this._setupMiddleware();
  }
github elmadev / elmaonline-site / src / server.js View on Github external
//
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known.
// -----------------------------------------------------------------------------
global.navigator = global.navigator || {};
global.navigator.userAgent = global.navigator.userAgent || 'all';

//
// Register Node.js middleware
// -----------------------------------------------------------------------------
app.use(express.static(path.resolve(__dirname, 'public')));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.use(fileUpload());

//
// Authentication
// -----------------------------------------------------------------------------

app.use(session({ secret: 'grant' }));
app.use(
  grant({
    ...config.grant,
  }),
);

if (__DEV__) {
  app.enable('trust proxy');
}
github kevoj / nodetomic-api-swagger / src / core / express.js View on Github external
export async function index(app) {

  app.use(bodyParser.json({ limit: '5mb' }));
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(fileUpload());
  app.use(cookieParser());
  app.use(methodOverride());
  app.use(compression());
  app.use(helmet());
  app.use(cors({ origin: true, credentials: true }));

  if ("twitter" in config.oAuth && config.oAuth.twitter.enabled)
    app.use(session({ secret: config.secret, resave: false, saveUninitialized: false }));

  app.use(passport.initialize());
  app.use(passport.session());

  // Morgan
  if (config.log)
    app.use(morgan('dev'));
github Twilio-org / phonebank / server / config / routes / contact_lists.js View on Github external
import express from 'express';
import fileUpload from 'express-fileupload';
import { saveNewContactList,
         updateContactListById,
         getAllContactLists,
         getContactListById,
         addContactToContactList } from '../../controllers/contact_lists';
// add updateContactInvalidNumberById
const router = express.Router();

router.route('/').get(getAllContactLists);
router.route('/').post(fileUpload(), saveNewContactList);
router.route('/:id').get(getContactListById);
router.route('/:id').put(updateContactListById);
router.route('/:id/contacts').post(addContactToContactList);

export default router;
github timzprof / book-a-meal / api / index.js View on Github external
import Meal from './models/meals';
import Menu from './models/menu';
import Order from './models/orders';
import OrderItem from './models/orderItem';
import swaggerDocument from './swagger.json';

config();

const app = express();

const PORT = process.env.PORT || 4000;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
app.use(fileUpload());
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api/v1', Routes);

User.hasMany(Order, { constraints: true, onDelete: 'CASCADE' });
User.hasMany(OrderItem, { constraints: true, onDelete: 'CASCADE' });
Order.belongsTo(Caterer, { constraints: true, onDelete: 'CASCADE' });
Meal.belongsTo(Caterer, { constraints: true, onDelete: 'CASCADE' });
Menu.belongsTo(Caterer, { constraints: true, onDelete: 'CASCADE' });
OrderItem.belongsTo(Meal, { constraints: true, onDelete: 'CASCADE' });

sequelize
  .sync()
  .then(() => {
    console.log('DB Connection has been established');
    app.listen(PORT, null, null, () => {
      app.emit('dbConnected');
github codejamninja / generator-trailblazer / app / templates / template / shared / config / web.js View on Github external
isImage: (value, file) => {
          let valid = false;
          const validMimetypes = [
            'image/png',
            'image/jpeg',
            'image/gif',
            'image/bmp'
          ];
          _.each(validMimetypes, (validMimetype) => {
            if (file.mimetype === validMimetype) valid = true;
          });
          return valid;
        }
      }
    }),
    fileUpload: fileUpload({
      limits: { fileSize: 50 * 1024 * 1024 },
      safeFileNames: true,
      preserveExtension: true
    }),
    errorHandler(err, req, res, next) {
      if (err) return res.error(err);
      return res.error(new Error('Unknown error'));
    }
  },

  cache: 31557600000,

  port: process.env.PORT || 3000,

  host: process.env.HOST || '0.0.0.0',
github thanhle09t2bkdn / blog-server-es7 / index.js View on Github external
import {env} from './server/config';
import Express from 'express';
import BodyParser from 'body-parser';
import Path from 'path';
import Morgan from 'morgan';
import Cors from 'cors';
import {WebRouter, ApiRouter} from './server/routes';
import {error} from './server/middlewares';
import Compress from 'compression';
import FileUpload from 'express-fileupload';
const app = Express();
app.use(FileUpload({
    limits: {fileSize: 50 * 1024},
}));
app.use(Cors());
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({extended: true}));
app.use(Compress());
app.use(Express.static(Path.resolve(__dirname, 'server', 'public'), {maxAge: 31557600000}));
app.set('view engine', 'ejs');
app.set('views', Path.join(__dirname, 'server', 'views'));
app.disable('x-powered-by');
if (env === 'development') {
    app.use(Morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));
}


app.use('/api', ApiRouter);

express-fileupload

Simple express file upload middleware that wraps around Busboy

MIT
Latest version published 4 months ago

Package Health Score

58 / 100
Full package analysis

Popular express-fileupload functions