title: Error 413 payload too large when upload image
body: <p>I'm trying to upload an image from local by using <strong>base64</strong> to do image detection.<br/>
  And everything works fine in localhost and postman.<br/>
  But after deploying, I got CROS error.</p>
  <p>I've already got cors middleware in <code> server.js</code></p>
  <pre><code>const express = require(&quot;express&quot;);    
  const cors = require(&quot;cors&quot;);
  const bodyParser = require(&quot;body-parser&quot;);
  
  const app = express();
  
  app.use(cors());
  
  app.use(bodyParser.json({ limit: &quot;10000kb&quot;, extended: true }));
  app.use(bodyParser.urlencoded({ limit: &quot;10000kb&quot;, extended: true }));
  </code></pre>
  <p>The cors middleware works fine when fetching image with url,<br/>
  But when I tried to <strong>upload image from local</strong> by using <strong>base64</strong>, the console shows:</p>
  <pre><code>No 'Access-Control-Allow-Origin' header is present on the requested resource.
  </code></pre>
  <p>Here's the solution I've tried:</p>
  <ol>
  <li>cors-anywhere</li>
  </ol>
  <pre><code>App.js
  
      const proxyUrl = 'https://cors-anywhere.herokuapp.com/';
      
      fetch(proxyUrl + API_CALL.IMAGE_URL, {
            method: 'post',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify({
              inputLink: inputLink,
              inputMethod: inputMethod
            }),
            credentials: 'include'
          })
  </code></pre>
  <p>It then shows <code>413 payload too large</code>.</p>
  <p>Since there's no error when testing in localhost and postman, I found out some articles said it might still be the cors error.</p>
  <ol start="2">
  <li>CORS preflight</li>
  </ol>
  <p>server.js</p>
  <pre><code>    const corsOptions = {
          origin: 'https://front-end-url/',
          methods: 'GET, POST, PUT',
          credentials: true,
          allowedHeaders: 'Content-Type,Authorization',
          exposedHeaders: 'Content-Range,X-Content- Range'
      };
      app.options('/imageUrl', cors(corsOptions));
  </code></pre>
  <p>It shows error:</p>
  <pre><code>CORS policy: Response to preflight request doesn't pass access control check: 
  The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' 
  when the request's credentials mode is 'include'
  </code></pre>
  <ol start="3">
  <li>After I remove <code>credentials: 'include'</code>, it shows <code>413 payload too large</code> again.</li>
  </ol>
  <p>I'm so confused... Does anyone know how to fix it? Thank you.</p>