English 中文(简体)
我怎样才能在Express.js拦截一个多部分文件流?
原标题:How can I intercept a multipart file stream in Express.js?

以下列例子为例

a href="https://github.com/visualmedia/ description/blob/master/examples/ multipart/ app.js" rel="不跟随 Nofollow noreferrer">https://github.com/visualmedia/ decess/blob/master/examples/multipart/ap.js 死链接

Expressjs似乎做了所有幕后的工作,保存了文件并将其全部交给你。 我怎样才能拦截和操纵原始流流? 具体地说,我想把流引到写流上, 这样我就可以把它连接到一个写流上。

最佳回答

您不能, 除非您制作了一个使用巨大的中间器件, 并在那里拦截流( 解决办法是用自定义的软件来改变Express使用的身体 Parker) 。

请在以下文件中查看您的情况: @a href="https://github.com/senchalabs/connect/blob/master/lib/middleware/mulpart.js" rel="nofollown noreferrer" >https://github.com/senchalabs/connect/blob/master/lib/middleware/mulpart.js dead link

注意没有全球事件可以联系到

问题回答

您可以使用这个:

app.use(express.multipart({ defer: true }));

然后,在路线上:

app.post( /upload , function (request, response, next) {
  request.form.onPart = function (part) {
    // Default handling for non-files
    if (!part.filename) return form.handlePart(part);

    // part is a stream of the file
  };

  request.form.parse(request, function (error) {
    if (error) return next(error);
  });
});




相关问题
c# multipart/form-data submit programmatically

So got an small problem. Im creating an small application to automate an form submission on one website. But the bad thing is that they are using multipart/form-data for that. There is no file ...

Help, don t know what s wrong with my HTTP multipart POST

POST /upload HTTP/1.1 Host: assets.drop.io User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2 009042316 Firefox/3.0.10 Accept: text/html,application/xhtml+xml,application/...

Creating a post request including a multipart file upload

I am writing a simple snippet which sends a simple post request. Currently I am building the request like so: // Construct data String data = URLEncoder.encode("param1", "UTF-8") + "=" + ...

Load testing multipart form

I m trying to load-test a Rails application using JMeter. A critical part of the application involves a form that includes both text inputs and file uploads. It works fine in a browser, but when I ...

Trouble uploading to twitpic

I am trying to upload a photo using the API and am having an issue that I hope you can help me with. Below, I have pasted the http request to the API (minus the twitter username/password). I am ...

Browser support of multipart responses

I would like to create a HTTP response, using multipart/mixed, but I m not sure which browsers support it; and if it s as convenient as it sounds, from the client s point of view. To be honest, I do ...

热门标签