Skip to content

Commit

Permalink
Merge pull request #1836 from hackmdio/bugfix/uploadimage-form
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley2058 authored Dec 26, 2023
2 parents 070808b + 1b1ff89 commit f58c669
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/imageRouter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ function checkImageValid (filepath) {

// upload image
imageRouter.post('/uploadimage', function (req, res) {
var form = new formidable.IncomingForm()

form.keepExtensions = true
var form = new formidable.IncomingForm({
keepExtensions: true
})

form.parse(req, function (err, fields, files) {
if (err || !files.image || !files.image.path) {
if (err || !files.image || !files.image.filepath) {
response.errorForbidden(req, res)
} else {
if (config.debug) {
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image))
}

if (!checkImageValid(files.image.path)) {
if (!checkImageValid(files.image.filepath)) {
return response.errorForbidden(req, res)
}

const uploadProvider = require('./' + config.imageUploadType)
uploadProvider.uploadImage(files.image.path, function (err, url) {
uploadProvider.uploadImage(files.image.filepath, function (err, url) {
// remove temporary upload file, and ignore any error
fs.unlink(files.image.path, () => {})
fs.unlink(files.image.filepath, () => {})
if (err !== null) {
logger.error(err)
return res.status(500).end('upload image error')
Expand Down

0 comments on commit f58c669

Please sign in to comment.