file upload does not exceed 64kb - multer or formidable - nodejs, nuxt

Viewed 177

Good afternoon,

I'm uploading a file for a route and uploading. I've tried it with formidable and now with multer, but only 64kb of the file is copied. Example: if the file is 100kb, only 64kb and the rest is lost.

When placing a cconsole.log ("passed"), it only shows files below 64kb, the largest ones don't even enter. Thank you very much in advance.

code client:

<template>
    <input type="file" name="image" id="image" @change="uploadDocument">
</template>


<script>
import { mapState, mapGetters } from "vuex";

export default {
  name: "teste",
  data() {
    return {
      fileError: "",
      selectedFile: [],
      selectedDocType: [ "KYC_DOCUMENT", "KYC_SELFIE", "KYC_ADDRESS"],
      imgSrc: "",
      Index: -1,
    };
  },
  methods: {
    async uploadDocument(event) {
        const input = event.target;

        const formData = new FormData();
    
        formData.append("kycImage", input.files[0]);

        let config = {
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'multipart/form-data;',
            }
        };

        const { data } = await this.$axios.post("/upload/sendFile", formData, config);
     }
  }
};
</script>

code server:

var express = require('express');
var router = express.Router();
const bodyParser = require('body-parser');
const multer = require('multer');

const upload = multer({ dest: 'C:\\Users\\Giovane\\Documents\\upload' })

var app = express();
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 }));

router.post('/sendFile', upload.single('image'), function(req, res, next){
    console.log(req)
});

module.exports = router;

OBS: No error appears on either the server or the client

1 Answers

I recently had the same issue and now discovered a solution. In a middleware executing before multer I set req.connection to a mysql connection object.

It seem like requests to an express server which are larger than 64kb are send as a stream and therefore they have to be processed with the express-connection object in the request.

Related