Click here to Skip to main content
15,935,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,
i'm a newbie tryn to develop a WEB App in Node JS. What i'm doing is downloading a PDF file from a FTP server and merging it(using PDF Merger plugin) with an other one coming from the Front End User. Here is the part of my code throwing the error:
JavaScript
<pre>ftps.on('ready', function () {
        let path = "/var/www/html/Scansioni/" + pathFilePdf;
        ftps.get(path, async function (err, fileStream) {

            if (err) throw err;
            console.dir(err);
            
            console.log(typeOf(fileStream));
            merge.add(fileStream); // ----->throws error

            let c = params.acquiredFiles.length;
            for (let i = 0; i < c; i++) {
                const acquiredFile = params.acquiredFiles[i];
                const pdfBuffer = Buffer.from(acquiredFile, 'base64');
                merge.add(pdfBuffer);
            }

            const resultingBuff = await merge.saveAsBuffer();
            
            ftps.put(resultingBuff, path, function (err) {

                if (err) throw err;
                console.dir(err);
                ftps.end();

                response.result = "success";
                response.status = 200;
                res.status(200).json(response);
            });

        });

    });



Here is shortly the error coming in the server console:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Socket


What I have tried:

Now i've understood that the problem is related to the type of variable fileStream coming from the ftps.get() and that the method add() of PDF Merger is waiting for another kind. I've tried to transform it in base64 buffer with
Buffer.from(fileStream,'base64') and adding it but still getting the same error as above. Could someone help me?
Thank you all in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900