12

I am serving up my web application using NodeJS server (ExpressJS) currently. One of the new requirements is for the users to be able to upload large videos (potentially in gigs) to the server. They will later then be able to download them again. Could I achieve this with the current stack?

I came across tutorials using Multer JS with "multipart/form-data" specified by the front-end. If I use this, would my Express be able to serve up other HTTP requests while writing a giant single video file to the server's disk?

3 Answers 3

5

Having done this myself (~20GB files, without multer) I can recommend the following (Probably most of which you have considered, but for completeness):

  1. Choose an appropriate upload control (or write your own, but basically something that chunks up the data is best. I used plupload I think)

  2. On the server make an API to handle the received chunk data, and write it out to a temp location during upload (You may want to hash and check individual pieces as well).

  3. Once upload complete, check file (I used a hash generated by the client, and checked it against the uploaded data)

Sign up to request clarification or add additional context in comments.

2 Comments

Just curious, is there a reason you decided not to use multer?
I did it 4 / 5 years ago... don't think the project even existed (When I did it we were still doing a lot of HTML5 shimming with flash :O)
4

Multer should work fine. It'll stream the data as it comes in over HTTP to a file on disk. It won't lock up your server. Then in your endpoint you have access to that file location and can do whatever you need with it.

8 Comments

On a side note: Are you then just uploading that file to S3? If you are, you can actually have the client upload the file directly to S3. This will save your Node server from having to process GB's of data. And S3 can likely serve your files back to whomever faster than your own servers can.
Uploading to S3 seems like a good solution. Seeing as you are recommending it, it is safe to do this in terms of security I guess? Surely you wouldn't want anybody to start uploading files to your S3 so is there some kind of authentication scheme?
The client asks your API for an access token to S3. Your API basically creates this token using the S3 libraries Amazon provides. This is a temporary token that your client will then use to connect to S3 to upload a file. Once uploaded you can call back to your API with either the path or the identifier. Then your API can use the S3 file however it pleases.
There is a multer s3 plugin github.com/badunk/multer-s3 maybe can be useful
I am working with multer but it always loads the file into the memory first. Does not stream the data to the disk, any ideas?
|
0
    var express =   require("express");

    var app =   express();
    var async = require('async');
    var fs = require('fs');
    var client = redis.createClient();
    var multiparty = require('multiparty');
    var util = require('util');

    app.post('/',function(req,res){

        var form = new multiparty.Form();

        form.parse(req, function(err, fields, files) {

             client.get(fields.otp, function(err, reply) {
    var oldpath = files.file[0].path;
                          var newpath = path + files.file[0].originalFilename;
                          fs.rename(oldpath, newpath, function (err) {
                            if (err) throw err;
                            res.write('File uploaded and moved!');
                            res.end();
                          });
    }
    }



app.listen(2001,function(){
    console.log("Server is running on port 2001");
});

1 Comment

I appreciate the code, but its not clear to me on how multiparty differs from multer. Its also not clear at all why you are using the redis client stuff. No client in the multiparty example. Hint: it's okay to add comments to make this stuff helpful and clear to others. Why is this recommendation better (or equal) to the checked answer above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.