%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestUpload.aspx.cs" Inherits="AVA.ResourcesPlatform.WebUI.Test.TestUpload" %>
Server side 服务端:
// 获取文件
app.get('/file', function(req,res){
var fieldname = "fileToUpload";
var saveToWhere = path.join(__dirname + '/public/', path.basename(fieldname));
if( fs.existsSync(saveToWhere)){
var stats = fs.lstatSync(saveToWhere);
return res.json(stats);
}
res.status(404).end();
});
// 上传文件
app.post('/upload',function(req,res) {
var filesize = req.query.filesize;
var busboy = new Busboy( {
headers: req.headers ,
limits:{
// fileSize:
}
});
busboy.on('file', function(fieldname, file,filename, encoding, mimetype){
var saveToWhere = path.join(__dirname + '/public/', path.basename(fieldname));
if( fs.existsSync(saveToWhere)){
// 如果文件存在 判断文件大小 增加写入
var stats = fs.lstatSync(saveToWhere);
if(filesize){
if(stats.size < filesize){
file.pipe(fs.createWriteStream(saveToWhere, {start:stats.size }));
}
}
}else{
file.pipe(fs.createWriteStream(saveToWhere));
}
});
busboy.on("finish", function(){
res.send("ok");
})
req.pipe(busboy);
});
To view this page ensure that Adobe Flash Player version 11.1.0 or greater is installed.