Guest User

Untitled

a guest
Dec 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. router.post('/uploadImage', (request, response) => {
  2. const form = new formidable.IncomingForm()
  3. const address = path.dirname(__filename).split('/')
  4.  
  5. address.pop()
  6.  
  7. form.uploadDir = `BACKEND/imagenes/`;
  8. form.keepExtensions = true;
  9. form.maxFieldsSize = 10 * 1024 * 1024;
  10. form.multiples = true; //multiples archivos
  11.  
  12. form.parse(request, (err, fields, files) => {
  13. if (err) {
  14. response.json({
  15. message: 'error al subir la imagen',
  16. data: []
  17. })
  18. }
  19.  
  20.  
  21. let data
  22.  
  23. console.log('FILES = '+files)
  24.  
  25. let filesPath
  26.  
  27. if (Array.isArray(files)) { //Si se han subido mas de un archivo, es decir, si es un Array de archivos
  28. filesPath = files.map(file => file.path)
  29. } else {
  30. filesPath = files.path
  31.  
  32. }
  33.  
  34.  
  35.  
  36. response.json(data)
  37. })
  38. })
Add Comment
Please, Sign In to add comment