I am trying to create a ReadableStream object from a request, which eventually I want to pass it into the attachment variable for mailgun-js's data object:
var fileStream = null;
request(String(url)).pipe(fileStream);
msg.attachment = new mailgun.Attachment({
data: fileStream,
filename: 'my_custom_name.png',
knownLength: fileStat.size,
contentType: 'image/png'});
What's the correct way to do this?
Not tested, but worth giving a try:
request()doesn't seem to inherit fromStream, so directly passing it asdataproperty won't work. Instead, aPassThroughstream is created, which inherits from bothReadableandWritable.The
Readablepart will be used by the Mailgun class, and theWritablepart will get the HTTP response data piped into it.