Different encoding in file retrieved via curl or node request module

170 views Asked by At

I am currently having problems with what I think might be the encoding of a retrieved file from the unoconv service. I am using a this docker container which provides uniconv as a webservice and trying to convert docx files do pdf I am being successful using curl as the example given, but when I try to integrate it into my app using the node request-promise module I can get a response but the generated file seems to have a different encoding and it's just an empty pdf.

This is my request (which I think is ok):

const newFile = await rp(options)
        .then(resp => {
            const base64 = Buffer.from(resp.body, 'base64');
            fs.writeFileSync(`${process.cwd()}/uploads/${temporaryName}.pdf`, resp.body);

            const fileToSave = {
                data: base64,
                contentType: 'application/pdf',
                extension: 'pdf',
            };

            return fileToSave;
        })
        .catch(err => {
            console.log(err);
        });

When I access the saved file I got the output on the left, whilst the one on the right is the one retrieved through curl:

enter image description here

0

There are 0 answers