Я решил таким образом:
В шаблоне .html файла
<script type="text/x-red" data-template-name="...">
<input id="myFile" type="file" name="fileToParse">
<input id="file-submit" type="submit" value="Import data from file" name="submit">
...
oneditprepare: function () {
$('#file-submit').click(function (e) {
var fd = new FormData();
fd.append('file', $('#myFile')[0].files[0]);
var file = fd.get('file');
var blb = file.slice();
var reader = new FileReader();
// This fires after the blob has been read/loaded.
reader.addEventListener('loadend', (e) => {
var fileData = e.srcElement.result;
console.log(fileData);
$.ajax({
url: '/mynode/file-parse',
data: {fileData: fileData},
method: 'POST',
success: function (data) {
populateForm(data);
}
});
});
// Start reading the blob as text.
reader.readAsBinaryString(blb);
});
И в .js:
RED.httpAdmin.post("/mynode/file-parse", function (req, res) {
var output = [];
var fileData = req.body.fileData;
// ... parse fileData end produce output
res.json(output)
});