node application stream file upload directly to am

2019-04-14 16:50发布

问题:

This question already has an answer here:

  • How to upload a file from the browser to Amazon S3 with node.js, Express, and knox? [closed] 6 answers

Hello :) I'm looking at the feasibility of having my node application stream HTTP POST file uploads directly through to an Amazon S3 Bucket.

I'm looking at using Formidable and Knox for this.

The part I'm unsure about is that S3 requires that you know the total number of bytes in the file before transmission.

Would I be right in thinking that the only way to accomplish this then would be to use the HTML5 File API (And possibly an ActiveX control on Internet Explorer) to check the file size on the client and send this as part of the HTTP POST request ?

回答1:

With the recent CORS support, you can easily send files directly to s3, without your server having to handle anything.

I recently wrote a short tutorial, with rails, but again the server is just used to compute some keys, so adapting it to express shouldn't be hard at all.

But with such a solution, you'll need to use the jQuery File Upload plugin, and you probably won't need knox

https://pjambet.github.io/blog/direct-upload-to-s3

Hope it'll help you.



回答2:

Maybe this can help - I made this to use the JQuery File Upload plugin upload directly to S3. I did not need to check the size of the file.

https://gist.github.com/3995819