Created
February 1, 2018 15:38
-
-
Save UrusuLambda/27234753c2283363d329d171e48d7540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/', upload.single('imgfile'), function (req, res) { | |
var fextention = path.extname(req.file.originalname).toLowerCase(); | |
var targetPath = uuid.v4() + fextention; | |
var tempPath = req.file.path, | |
targetResolvedPath = path.resolve('./uploads/'+targetPath); | |
//tempPathに置かれている画像ファイルをeasyimgのrescropでwidthを1000にする. | |
if ( fextention === '.png' || fextention === '.jpg' || fextention === '.bmp') { | |
easyimg.rescrop({ | |
src:tempPath, dst:targetResolvedPath, width:1000 | |
}).then(function(image){ | |
res.json({image_url:targetPath}); | |
}); | |
} else { | |
//png jpg bmpじゃなかったらファイル削除 | |
fs.unlink(tempPath, function () { | |
if (err) throw err; | |
res.json({message:"Only png bmp jpg files are allowed"}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment