## Here is my Unsucessfull approach ##
----------
> Server side code
> Recieve Video stream from client and save it in .mp4 format
var express = require('express');
var app = global.app = exports.app = express();
var fs = require('fs');
app.post('/video_main', (req, res, next) => {
console.log(req)
const video_stream = fs.createWriteStream('vde.mp4')
req.pipe(video_stream)
//save the video stream to vde.mp4
})
app.use('*', function(req, res, next) {
return res.status(404).json({
'status': 'FAILURE',
'message': 'Not found'
})
})
app.listen('3000');
// server listening on http://localhost:3000/
----------
> Client side code
> send video stream to server
const request = require('request')
const fs = require('fs')
var readablestream = fs.createReadStream('SampleVideo_1280x720_1mb.mp4')
const write = fs.createWriteStream('test.mp4');
const r = request.post("http://localhost:3000/video_main");
r.pipe(readablestream);
/*
*/
代码的主要错误是在客户端,最后一行应该是
readablestream.pipe(r);
因为您正在将数据从可读流传输到请求中。
为了将来的引用,您应该始终遵循约定:
readstream.pipe(writestream);
I figured this out by analyzing the code on this github, which has pretty nice implementation of file transfer over html:
https://gist.github.com/alepez/9205394
我是一名优秀的程序员,十分优秀!