0

I want to upload a file (in this case an usdz file) with a post request from an nodejs server, but can't get it to work.

const FormData = require('form-data')
const fs = require('fs')
const https = require('https')

const form = new FormData();
form.append('file', fs.createReadStream('./Store/data.usdz'));

const postOptions = {
    host: myserver.com,
    path: '/mypath/recive?token=' + CONFIG.authToken,
    method: 'POST',
    headers: form.getHeaders()
};

const postRequest = https.request(postOptions, res => {
    res.once('data', d => {
        console.log('sucess');
    })
    res.once('error', (error) => console.log(error));
});


form.pipe(postRequest);

postRequest.end();

0 Answers0