一个上传图片返回url的nodejs程序,返回
{
"name": "name",
"url": "/uploader/upload"
}
怎么才能将本地路径转化成http路径呢,比如 example.com/upload/a.jpg
router.post('/', function (req, res) {
if (req.busboy) {
var name = ''
req.busboy.on('file', function (fieldname, file, fileName, encoding, mimeType) {
name = fileName
var stream = fs.createWriteStream(path.join(__dirname, '../', uploadPath, fileName))
file.pipe(stream)
console.log('uploading %s -> %s', fileName, stream.path)
}).on('finish', function () {
res.send({
name: 'name',
url: path.join(uploadPath, name)
})
})
req.pipe(req.busboy)
} else {
console.log('uploadFile - busboy undefined.')
res.status(502)
}
})