const https = require('https');
const options = {
'method': 'POST',
'hostname': 'chinadatapay.apistd.com',
'path': '/img/upload?key=your_access_key_here',
'headers': {
'Content-Type': 'multipart/form-data'
}
};
const req = https.request(options, (res) => {
const chunks = [];
res.on("data", (chunk) => {
chunks.push(chunk);
});
res.on("end", (chunk) => {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", (error) => {
console.error(error);
});
});
const postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"data\"; filename=\"file\"\r\nContent-Type: \"{Insert_File_Content_Type}\"\r\n\r\n" + fs.readFileSync('/path/to/file') + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
req.write(postData);
req.end();