Tag: busboy

节点js的busboy不发射事件与angularjs $ http后

Busboy似乎只是卡在那里。 我testing了所有3个事件(文件,字段,完成),但没有发射任何东西。 我的angular码在下面。 $http({ method : 'POST', url : mublAConfig.server + '/api/v3/user/friend', headers : { 'Content-Type' : 'application/x-www-form-urlencoded', 'Authorization' : access_token }, transformRequest : function(obj) { var str = []; for (var p in obj) { str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p])); } return str.join('&'); }, data : { id : $scope.writes[0].input, say : $scope.writes[1].input } […]

Connect-busboy:当pipe道文件写入蒸汽时,根据types文件为空或不正确

我正在使用connect-busboytesting一个简单的file upload。 我注意到,当我上传一个PNG格式的文件,file upload,但内容不正确 – 我无法打开它。 我已经在源文件和目标文件上做了md5sum,它们是不同的。 当我上传一个仅包含15个字节的文本文件时,我看到文件被上传到./public/目录,但是它是空的。 客户端代码: <form method="post" enctype="multipart/form-data" action="/api/upload"> <input type="file" name="thumbnail"/> <input type="submit"/> </form> 服务器端 //includes omitted for readability var Busboy = require("connect-busboy"); app.use(Busboy()); //Add entires to places app.post("/api/upload", function (req, res, next) { req.pipe(req.busboy); var filesNames = []; req.busboy.on('file', function(fieldname, file, filename) { file.on("data", function(data) { var fstream = […]

node.js – Busboy如何工作?

我对Busboy模块有些困惑。 我不明白在哪里需要文件数据stream,因为它只接受请求标题作为参数?! 看看文档中的示例: var busboy = new Busboy({ headers: req.headers }); busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { //… // btw file is ReadableStream! });

ExpressJS Promise和EventEmitter之间明显的竞争状态

我有一个NodeJS / Expressnetworking应用程序,允许用户上传文件,然后使用Sequelize使用connect-busboy保存到我的数据库。 一旦完成,我想将用户redirect到给定页面。 但是,在我的Promise解决之前,Express已经返回了404的状态,即使我从来没有调用next() ,为了调用中间件链中的下一个处理程序,我认为这是强制性的,从而导致了404。 这是我的代码到目前为止: function uploadFormFile(req, res, next) { var documentInstanceID = req.params.documentInstanceID; // set up an object to hold my data var data = { file: null, documentDate: null, mimeType: null }; // call the busboy middleware explicitly // EDIT: this turned out to be the problem… of course this calls […]

如何处理Node.js中的中断file upload

当访问者在file upload到我的Node.js服务器时按下STOP,REFRESH或BACK或简单地closures浏览器时,就会出现问题。 将有一些垃圾文件留在服务器中。 为了解决这个问题,我试着将上传的文件保存到一个临时目录,并在下次访问者再次上传时删除这些文件。 但是,显然Node.js会locking上次上传的文件,从而阻止它被删除。 当我停止Node.js服务器时,文件locking将被释放,最终将被删除。 如何在不重新启动服务器的情况下删除垃圾文件? 我正在使用公务员包。

节点JS – 将数据从Busboystream式传输到AWS S3

我想通过ec2上传一个文件到s3。 我的第一个方法是 – 将文件完全上传到ec2,然后将该file upload到s3。 这种方法并不好,因为从ec2到s3的传输时间浪费时间。 目前我正尝试使用busboy上传stream来上传s3stream,以便上传到ec2,然后ec3到s3将同时完成,因为s3 “upload”方法支持stream上传Body。 这是我的代码 – router.post('/s3StreamUpload', function(req, res, next) { var busboy = new Busboy({headers: req.headers}); busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { console.log('Before Upload: ' + new Date()); console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' […]

busboy不发射领域,文件事件

在下面的代码中,只有完成事件调用。 var Busboy = require('connect-busboy'); app.use(Busboy()); app.post('/fileupload', function(req, res) { var fstream; req.pipe(req.busboy); req.busboy.on('error', function(err){ console.log(err); }); req.busboy.on('field', function(fieldname, val, valTruncated, keyTruncated) { console.log("fieldname: " + fieldname); }); req.busboy.on('file', function (fieldname, file, filename) { console.log("filename: " + filename); fstream = fs.createWriteStream(__dirname + '/files/' + filename); file.pipe(fstream); fstream.on('close', function () { res.redirect('back'); console.log("fileupload end"); }); }); […]

你如何通过node.jsstream向S3上传并向用户显示进度?

目标是: 能够从浏览器上传文件 能够直接上传到S3 将上传进度转发给浏览器 我花了一段时间来解决这个问题(并没有完全find一个答案,所有3在StackOverflow呢),所以张贴我的答案,以防其他人有同样的问题。 我愿意提供更好的解决scheme(我的速度非常可怕)。

不支持的内容typesImage / PNG

我试图上传一个图像文件在服务器上使用NodeJS busboy ,我得到这个错误: Service Listening for request on: 8080 Error: Unsupported content type: image/png at Busboy.parseHeaders (D:\ImageUploadService\node_modules\busboy\lib\main.j s:66:9) at new Busboy (D:\ImageUploadService\node_modules\busboy\lib\main.js:21:10) at D:\ImageUploadService\server.js:15:15 at Layer.handle [as handle_request] (D:\ImageUploadService\node_modules\expr ess\lib\router\layer.js:76:5) at next (D:\ImageUploadService\node_modules\express\lib\router\route.js:100: 13) at Route.dispatch (D:\ImageUploadService\node_modules\express\lib\router\rou te.js:81:3) at Layer.handle [as handle_request] (D:\ImageUploadService\node_modules\expr ess\lib\router\layer.js:76:5) at D:\ImageUploadService\node_modules\express\lib\router\index.js:234:24 at Function.proto.process_params (D:\ImageUploadService\node_modules\express \lib\router\index.js:312:12) at D:\ImageUploadService\node_modules\express\lib\router\index.js:228:12 以下是我的代码: app.post('/uploadImage',function(req,res){ var […]

NodeJS与连接busboy错误,“TypeError:不能调用方法”的未定义“

我有这段代码: router.route("/post") .get(function(req, res) { … }) .post(authReq, function(req, res) { … // Get uploaded file var fstream req.pipe(req.busboy) req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { … var fileSuffix = mimetype.split("/")[1] // Get suffix, may not always be correct var tmpFileName = postCount + "." + fileSuffix var tmpFileURL = __dirname + "/tmp/" + […]