【发布时间】:2013-03-07 16:34:57
【问题描述】:
我为 nodejs 图片上传做了一个教程。
问题:nodejs把上传的图片存放在哪里?
我在本地工作 mit localhost:8888 (我是 nodejs 和编程的新手)
requestHandler.upload = function( response, request ) {
console.log( "Request for 'upload' is called." );
var form = new formidable.IncomingForm();
console.log( "Preparing upload" );
form.parse( request, function( error, fields, files ){
console.log( "Completed Parsing" );
if( error ){
response.writeHead( 500, { "Content-Type" : "text/plain" } );
response.end( "CRAP! " + error + "\n" );
return;
}
console.log("the path is: " +files.upload.path);
fs.renameSync( files.upload.path, "/tmp/" + files.upload.name );
response.writeHead( 200, { "Content-Type" : "text/html" } );
response.write( "received image <br />" );
response.end( "<img src='/show?i=" + files.upload.name + "' />" );
});
};
【问题讨论】:
-
我对强大的了解不多,但是
console.log("the path is: " +files.upload.path);? -
我想查看文件的位置,它说:/tmp/7fa95b95b9f......我不明白
-
嗯,这不是很明显吗?它在 /tmp/7fa95b95b9f... 这就是路径。
-
Linux下上传到/tmp文件夹,文件名随机选择。
-
OMG 没看出我的tmp和系统的tmp有什么区别,你是对的,现在我找到了,thx :)