我使http代理程序檢查http url,如果它是下載鏈接(content-type:octet-stream),我會得到響應並將響應中繼給其他計算機通過使用request.post和其他計算機下載文件與http代理給出的響應。nodejs pipe https對request.post和寫入文件的響應
讓我們假設Web代理計算機是A,它是A的代碼部分192.168.5.253
if(contentType && (contentType== "application/octet-stream" || contentType == "application/gzip")){
console.log("remoteRes##app",remoteRes);
let filepath = req.url.split('/');
let FileName = getFilename(remoteRes, filepath);
let writeStream = fs.createWriteStream(FileName);
/*remoteRes is octect-stream response.
I can get file buffer If I use remoteRes.on(data, chunk => {...})*/
remoteRes.pipe(writeStream); //It works but I want to send file buffer to B without writing file.
.........
我可以下載A.文件,但我要發送此響應PC B( 192.168.5.32:10001)服務器。 所以我想流是這樣的:
remoteRes.pipe(request.post('http://192.168.5.32:10001/upload));
這是服務器B的一部分(192.168.5.32)代碼
router.post('/upload', (req, res, next) => {
let wstream = fs.createWriteStream('ffff.txt');
req.pipe(wstream); //It dosen't work, but I want to do like this.
})
我想在router.post filebuffer( '/上傳' )。它不管是後置還是放。 我看到,當我使用remoteRes.pipe(request.post('http://192.168.5.32:10001/upload)); ,我看到來自ServerA的請求到達ServerB。但是我無法在ServerB中獲取文件緩衝區。 總之,我想管道響應request.post。
1)** A **獲取文件並將其發佈到** B ** ** B **將其寫入文件並回復到源自** A **的帖子,這是場景? –
EMX
通過request.post向B寫入文件緩衝區的管道響應,或者將B寫入B文件。我不需要回答。 – jijijijiji