V
V
Vladimir Mukovoz2017-09-16 15:23:04
HTML
Vladimir Mukovoz, 2017-09-16 15:23:04

How to save a file received via post?

The file is large, from 100MB to 1GB, so I don't want to keep it in RAM, that is, I need to save it to disk for temporary use. How to take it correctly, I have express, I looked at the documentation on the official site and did not master it, please explain to whom it is not difficult.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Mukovoz, 2017-09-17
@castomi

In general, here is a solution I got, maybe it will be useful to someone.

const express = require('express'), // Web сервер
app = express(), // Привязываем express к нашему "приложению"
multiparty = require('multiparty'); // Для сохранения файла

// Обработчик запросов
app.post('*', function(req, res) {
  var form = new multiparty.Form(); 
  form.parse(req, function(err, fields, files) { 
    console.log(files.txt[0].path); // Выводим в консоль адрес файла(txt это значение поля name, то есть в данном случае name="txt")
  })
});

txt is the value of name in the imput to be saved.

A
Alexander, 2017-09-16
@NeiroNx

And it seems to be not stored in the RAM, but as a temporary file
https://www.w3schools.com/nodejs/nodejs_uploadfiles.asp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question