小编Gak*_*eda的帖子

对createWriteStream的错误处理

我正在使用Node.js实现文件上传,并且我的代码在正常情况下可以正常工作。

但是,当我使它无法写入文件(例如,将其写入不存在的目录)时,它将调用错误处理程序fstream.on('error', ...),但它会卡住并且永远不会继续。

我以为通过打开传入流的管道,busboy继续进行处理的下一部分,但是似乎并非如此。

我想运行相同的内容busboy.on('end')来响应浏览器(带有一些错误信息),但是如何调用它呢?

var express = require("express");
var Busboy = require('busboy');
var fs = require('fs');
var upload = require('./upload');
var Path = require('path');
var app = express();

app.get("/", function(request, response) {
    response.writeHead(200, { Connection: 'close'});
    response.end('<html><body>' +
        '<form action="/upload" method="post" enctype="multipart/form-data">' +
        ' <input type="file" name="filefield">' +
        ' <input type="submit">' +
        '</body></html>');
});

app.post("/upload", function(request, response) {
    // request.files will contain the uploaded file(s),
    // keyed by the input name (in this …
Run Code Online (Sandbox Code Playgroud)

node.js

5
推荐指数
1
解决办法
9659
查看次数

标签 统计

node.js ×1