跳到主要内容
CNode

分享一个node结合uploadify的异步上传例子。

社区
Ffyddaben发布于 13 年前最后回复 12 年前
590550

服务器端配置: app.js==> app.use(express.bodyParser({ keepExtensions: true, uploadDir: __dirname + '/public/upload'})); index.js==>

`exports.upload = function(req, res){

     var fileDesc=req.files;

 var imgname=fileDesc.Filedata.name;
 
     var path=fileDesc.Filedata.path;//这里是本地路径D://upload/..jpg
 
     var index=path.indexOf(constant.uploadFile);//配置的放置文件的文件夹名字
 
     var name=path.substring(index);
 
 var imgurl=constant.DomainUrl+":"+constant.DomainPort+"/"+name;
 
 res.send(imgurl);//返回服务器端地址

};`

前台配置: test.js==>

$(function() {
	$('#file_upload').uploadify({
		 'swf'     : '/images/uploadify.swf',
		 'formData':{
	            'userid':'用户id',
	            'username':'用户名',
	            'rnd':'加密密文'
          },
          'cancelImg ':'/images/uploadify-cancel.png',
          'fileTypeExts' : '*.gif; *.jpg; *.png',
          'simUploadLimit ':'2',
		  'uploader' : '/fileupload',
		  'onUploadSuccess' : function(file, data, response) {
		          var img="<img src=\""+data+"\"/>";
		        
                              $("#img_box").append(img);
		        }
	});
});

html页面:

<link rel="stylesheet" type="text/css" href="/stylesheets/uploadify.css">
<style type="text/css">
    .input_frame{
    	height: 70px;
    }
    .img{
    	width: 550px;
    	position: absolute;
    	margin-top: 50px;
    }
    .img img{
    	width: 100px;
    	height: 100px;
        margin-left: 10px;
        z-index: -99;
    }
</style>

<div class="input_frame">
   <pre><input type="file" name="file_upload" id="file_upload" /></pre>
      </div>
查看回复

回复 (5)

F
fyddaben#512 年前

奥。我的app.js里面配置的上传路径,是fileupload

I
i5ting#412 年前

这是3的代码。。。。。

Q
qyy213#312 年前

路由是exports.upload 但是提交的是 'uploader' : '/fileupload',啊? 这怎么解释的通呢

Q
qyy213#212 年前

楼主代码运行不通啊

Y
yyp544784013#113 年前

求例子源码

参与回复

登录后即可参与回复。登录