repl.it
@Rafael_AngelAng/

CruelAnimatedCgibin

Nodejs

No description

fork
loading
Files
  • index.js
  • Packager files
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const fileUpload = require('express-fileupload')
const sharp = require('sharp')
const app = express();

app.get('/', (req, res) => {
  res.send(`
  <form action="/" method="post" encType="multipart/form-data">>
  <input id="input-b1" name="miImagen" type="file">

  <input type="submit">
  <form>
  `)
});

app.use(fileUpload({debug: true}));

app.post('/', (req, res) => {
let miImagen = req.files.miImagen;

sharp(miImagen.data)
  .resize(320, 240)
  .toBuffer()
  .then( fichero => {
    res.write(fichero)
  })
  .catch( err=> { res.write(err)})

})














app.listen(3000, () => {
  console.log('server started');
});