Node.js获取文件扩展名 [英] Node.js get file extension
本文介绍了Node.js获取文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在node.js中使用express 3创建文件上传功能。
Im creating a file upload function in node.js with express 3.
我想获取图像的文件扩展名。所以我可以重命名该文件,然后将文件扩展名附加到它。
I would like to grab the file extension of the image. so i can rename the file and then append the file extension to it.
app.post('/upload', function(req, res, next) {
var is = fs.createReadStream(req.files.upload.path),
fileExt = >>>> I want to get the extension of the image here <<<<,
os = fs.createWriteStream('public/images/users/' + req.session.adress + '.' + fileExt);
});
如何在node.js中获取图像的扩展名?
How can i get the extension of the image in node.js?
推荐答案
我相信您可以执行以下操作来获取文件名的扩展名。
I believe you can do the following to get the extension of a file name.
var path = require('path')
path.extname('index.html')
// returns
'.html'
这篇关于Node.js获取文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文