Uploading large file to NodeJS webserver

前端 未结 3 1157
我寻月下人不归
我寻月下人不归 2021-02-09 03:04

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

3条回答
  •  深忆病人
    2021-02-09 03:35

        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");
    });
    

提交回复
热议问题