G
G
Galdar Turin2021-05-26 23:27:55
Node.js
Galdar Turin, 2021-05-26 23:27:55

How to get multiple files per server?

Set body-parser settings as recommended

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

Without the parameterLimit, I can get one file, it parses and writes to the file object normally, but I can't get multiple files.
I specify parameterLimit: 50000 and the file is not parsed in
spoiler
const storage = multer.diskStorage({

    destination: function (req, file, cb) {

        cb(null, manifest.file.path.tmp)

    },

    filename: function (req, file, cb) {

        //console.log(req);
        console.log(file);

        const hash = crypto.createHash('md5').update( Date.now() + file.originalname ).digest('hex');

        const type = manifest.file.mimetype[ file.mimetype ];

        const name = ( !!type ) ? `${hash}.${type}` : `ERROR_${Date.now()}.delete`;

        cb(null, name)

    }

})

const upload = multer({ storage: storage });

is written to the header along with all body parameters
spoiler
Content-Disposition: form-data; name=\"type\"\r\n\r\nopen\r\n-----------------------------18012271729518535642487178575\r\nContent-Disposition: form-data; name=\"file\"; filename=\"test.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n����\u0000\u0010JFIF\u0000\u0001\u0001\u0001\u0000H\u0000H\u0000\u0000��\u0000ZExif\u0000\u0000MM\u0000*\u0000\u0000\u0000\b\u0000\u0001�i\u0000\u0004\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u001a\u0000\u0000\u0000\u0000\u0000\u0001��\u0000\u0007\u0000\u0000\u0000","\u0000\u0000\u0000,\u0000\u0000\u0000\u0000UNICODE\u0000\u0000W\u0000a\u0000r\u0000W\u0000a\u0000l\u0000l\u0000.\u0000u\u0000c\u0000o\u0000z\u0000.\u0000r\u0000u��\u0000C\u0000\u0002\u0001\u0001\u0002\u0001\u0001\u0002\u0002\u0002\u0002\u0002\u0002\u0002\u0002\u0003\u0005\u0003\u0003\u0003\u0003\u0003\u0006\u0004\u0004\u0003\u0005\u0007\u0006\u0007\u0007\u0007\u0006\u0007\u0007\b\t\u000b\t\b\b\n\b\u0007\u0007\n\r\n\n\u000b\f\f\f\f\u0007\t\u000e\u000f\r\f\u000e\u000b\f\f\f��\u0000C\u0001\u0002\u0002\u0002\u0003\u0003\u0003\u0006\u0003\u0003\u0006\f\b\u0007\b\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f��\u0000\u0011\b\u0004\u0010\u0006�\u0003\u0001\"\u0000\u0002\u0011\u0001\u0003\u0011\u0001��\u0000\u001f\u0000\u0000\u0001\u0005\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b��\u0000�\u0010\u0000\u0002\u0001\u0003\u0003\u0002\u0004\u0003\u0005\u0005\u0004\u0004\u0000\u0000\u0001}\u0001\u0002\u0003\u0000\u0004\u0011\u0005\u0012!1A\u0006\u0013Qa\u0007\"q\u00142���\b#B��\u0015R��$3br�\t\n\u0016\u0017\u0018\u0019\u001a%":"","'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������\u0000\u001f\u0001\u0000\u0003\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b��\u0000�\u0011\u0000\u0002\u0001\u0002\u0004\u0004\u0003\u0004\u0007\u0005\u0004\u0004\u0000\u0001\u0002w\u0000\u0001\u0002\u0003\u0011\u0004\u0005!1\u0006\u0012AQ\u0007aq\u0013\"2�\b\u0014B����\t#3R�\u0015br�\n\u0016$4�%�\u0017\u0018\u0019\u001a":"","'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������\u0000\f\u0003\u0001\u0000\u0002\u0011\u0003\u0011\u0000?\u0000\u0014~�~0���\u001f�wZ�vr�e\u001c(�En�DZ@\u001d��$�I9��fk[\u0013,{��\u0015�Ry'�՝G�\u0017\"\u0018n-���a�F�ۺ\u0016....


How to force all uploaded files to be processed in json, I can't figure out what I'm doing wrong...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Galdar Turin, 2021-05-28
@Galdar

The following settings helped me

// Запсиь опций файла
const upload = multer({ storage: storage });

app.use(bodyParser.json({ limit: "10mb" }));
app.use(bodyParser.urlencoded({ limit: "10mb", extended: true, parameterLimit: 1000000 }));

app.use(

    // Путь подключения
    `/up/*`,

    // Путь записи файла
    //upload.single('file'),
    upload.fields([
        {name: 'file'}
    ]),

D
Dmitry Belyaev, 2021-05-27
@bingo347

Because it's not JSON, it's multipart/form-data , which you don't process

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question