Open xoraingroup opened 5 years ago
Hi I could be mistaken, but I feel like request.put() does not actually return a stream you can write to. You have to make sure the request becomes a stream input and the request library knows it should return an input.
I did a quick google search but couldn't find a quick solution, maybe you will have more luck. Let me know if it worked!
@Mat-thieu Did you got the solution ?
@xoraingroup hey, were you able to solve this ?
any hope on the solution?
@Mat-thieu Did you got the solution ?
any solution how to sream output to bucket ?
@gulshan-dev123789
I don't have a solution, I only remember request
doesn't provide what you need here. It won't give you a writable stream.
Instead you can consider using the https package in node, which should return you a writable stream according to the docs https://nodejs.org/api/https.html#httpsrequestoptions-callback
probably looks something like this, but I didn't test it fully
const https = require('https');
const { URL } = require('url');
const putURL = new URL('https://upload-url');
const options = {
hostname: putURL.hostname,
path: putURL.pathname + putURL.search,
method: 'PUT',
headers: {
'Content-Type': 'video/mp4',
},
};
console.log(options);
// creates a writable stream
const req = https.request(options, (res) => {
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.error(`error`, e);
});
then you can pipe the request to ffmpeg
ffmpeg(video)
// your operations
.on('error', (error) => {
console.error(`ffmpeg error: ${error}`);
req.end();
})
.on('end', () => {
console.info('ffmpeg processing finished, finishing upload...');
req.end();
})
.pipe(req, { end: false });
Version information
Code to reproduce
(note: if the problem only happens with some inputs, include a link to such an input file)
Expected results
The stream should be piped to amazon AWS put url.
Observed results
Error: You cannot pipe to this stream after the outbound request has started. at Request. (/usr/local/lib/node_modules/request/request.js:495:26)
at Request.emit (events.js:198:13)
at Socket.Readable.pipe (_stream_readable.js:742:8)
at processCB (/Users/xorain/Git/personal/ffmpeg-logging/node_modules/fluent-ffmpeg/lib/processor.js:480:31)
at /Users/xorain/Git/personal/ffmpeg-logging/node_modules/fluent-ffmpeg/lib/processor.js:213:7
at FfmpegCommand.proto._getFfmpegPath (/Users/xorain/Git/personal/ffmpeg-logging/node_modules/fluent-ffmpeg/lib/capabilities.js:90:14)
at FfmpegCommand.proto._spawnFfmpeg (/Users/xorain/Git/personal/ffmpeg-logging/node_modules/fluent-ffmpeg/lib/processor.js:132:10)
at /Users/xorain/Git/personal/ffmpeg-logging/node_modules/fluent-ffmpeg/lib/processor.js:437:12
at /Users/xorain/Git/personal/ffmpeg-logging/node_modules/async/dist/async.js:473:16
at next (/Users/xorain/Git/personal/ffmpeg-logging/node_modules/async/dist/async.js:5329:29)
Emitted 'error' event at:
at errorOrDestroy (internal/streams/destroy.js:107:12)
at Request.onerror (_stream_readable.js:717:7)
at Request.emit (events.js:198:13)
at Request. (/usr/local/lib/node_modules/request/request.js:495:12)
at Request.emit (events.js:198:13)
[... lines matching original stack trace ...]
at FfmpegCommand.proto._spawnFfmpeg (/Users/xorain/Git/personal/ffmpeg-logging/node_modules/fluent-ffmpeg/lib/processor.js:132:10)
Checklist
I would like to know if its possible to directly pipe the output stream to a signed put url?? Just curious to know. Thank you