title: How to send the resized image from sharp back to user?
body: <p>I'm trying to make an image resizing API through <code>SharpJS</code> and my code follows as per the following</p>
  <pre><code>require('dotenv').config();
  
  const express = require('express');
  const sharp = require('sharp');
  const cors = require('cors');
  const formidable = require('formidable');
  
  const app = express();
  app.use(cors());
  
  app.use(express.json());
  
  app.post('/file', async (req, res) =&gt; {
      const form = formidable();
      form.parse(req, (err, fields, files) =&gt; {
          if (err) {
              next(err);
              return;
          }
          const imageInput = files.image.path;
          sharp(imageInput)
              .resize(128, 128)
              .toBuffer()
              .then((data) =&gt; {
                  console.log(data);
                  res.end(data)
              })
              .catch((err) =&gt; console.log(err));
      });
  });
  app.listen(4000);
  </code></pre>
  <p>What I actually want to know is how can I return the resized image to the client without actually saving it in server disk? The <code>data</code> is in the form of buffer as below, How do I convert it back to a file so that users could get their images and download it automatically.</p>
  <pre><code>// console.log(data)
  &lt;Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 80 00 00 00 80 08 06 00 00 00 c3 3e 61 cb 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 ... 12835 more bytes&gt;
  </code></pre>
  <p><strong>My React Code</strong></p>
  <pre><code>import React, {useState} from 'react'
  import axios from 'axios'
  function App() {
    const [state, setState] = useState({
      file: null
    })
    const fileHandler = e =&gt; {
      console.log(e.target.files[0]);
      setState({...state, file: e.target.files[0]})
  
    }
    const fileUploader = () =&gt; {
      const formData = new FormData()
      formData.append('image', state.file, state.file.name);
      axios.post('http://localhost:4000/file',formData).then((res) =&gt; {
        console.log(res.data)
      }).catch((err) =&gt; {
        console.error(err)
      })
    }
    return (
      &lt;div className=&quot;App&quot;&gt;
        &lt;input type=&quot;file&quot; onChange={fileHandler} /&gt;
        &lt;button onClick={fileUploader}&gt;Send File&lt;/button&gt;
      &lt;/div&gt;
    );
  }
  export default App;
  </code></pre>