I'm trying to read a video file from a URL (Amazon CloudFront) and stream it (upload it) with a POST request to Dailymotion using a NodeJS Lambda function.
Here's the code that I have:
https.get(
'https://cdn.mysite.com/video.mp4',
videoStream => {
videoStream.pipe(
https.request(
'https://upload-xx.xxx.dailymotion.com/upload?uuid=xxxxx&seal=xxxxx&extra=xxxxx', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
},
body: {
'Content-Disposition': 'form-data',
'Content-Type': 'video/mp4',
'file': videoStream
}
},
(response) => {
console.log('statusCode :', response.statusCode);
console.log('statusMessage:', response.statusMessage);
})
);
},
(response) => {
console.log(response);
}
);
Using the code above, I'm always getting this response from Dailymotion:
statusCode : 422
statusMessage: Unproccessable Entity
Based on Dailymotion documentation:
The video can actually be uploaded to the
upload_urlretrieved above by making a POST HTTP request using themultipart/form-datacontent type. The video data has to be contained in afilefield.
How can I pass the piped chunks as form-data to the POST request?