I've got a node server setup which accepts pdf uploads and uploads them to a hedera blockchain testnet.
app.post('/upload', upload.single('pdf'), function (req. res) {
uploadToBlockchain(req.file)
res.send('finished')
})
and a python script which does some processing on a file given a file buffer:
from Transformer import Transformer as tf
with open('file_path', 'rb') as pdf_file:
images = pdf_file.read()
a = tf.bytes_to_hash_array(images)
print(a)
Is there some way to link these two up, so that I can send the PDF data I received from node(req.file) and pipe it to the python script to process and return the results? I've tried a few things with child process but haven't managed to get the file open in python.
I've tried in the node server.js:
var pythonOut;
const python = spawn('python', ['Scripts/convert_pdf.py', req.file]);
python.stdout.on('data', function (data) {
pythonOut = data;
});
python.on('close', (code) => {
console.log(`child process close all stdio with code ${code}`);
console.log(pythonOut);
});
uploadToBlockchain(pythonOut);
Which if I read using sys.argv[1] in Python, gives me an [object Object] which I'm not sure how to open as a file to send to my transformer object. I've also tried sending req.file.buffer as an argument, but it simply sends a string of the buffer information rather than the actual bytes in the buffer.