SHARE
TWEET

Untitled

a guest Jan 24th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Joi = require('joi');
  2.  
  3. module.exports = {
  4.   method: 'post',
  5.   path: '/upload',
  6.   config: {
  7.     validate: {
  8.       payload: {
  9.         files: Joi.array().items(
  10.           Joi.any()
  11.         ).single().required()
  12.       }
  13.     },
  14.     payload: {
  15.       maxBytes: 1000 * 1000 * 5, // 5 Mb  
  16.       output: 'file',
  17.       parse: true
  18.     },
  19.     handler: async (request, h) => {
  20.       /**
  21.       * data structure will be:
  22.       * { path: '/var/folders/39/s48jqbvx31s98m5y8x4wr_h0d74j26/T/1548246811595-6726-4ff6112d1349194b',
  23.       * bytes: 202600, filename: 'mrscruff.jpg',
  24.       * headers: { 'content-disposition': 'form-data; name="files"; filename="mrscruff.jpg"', 'content-type': 'image/jpeg' } }
  25.       */
  26.       request.payload.files.forEach(file => {
  27.         console.log(file);
  28.       });
  29.       return { message: 'ok' };
  30.     }
  31.   }
  32. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top