在快速 js 中上传和调整图像大小时出现问题

Got issue with upload and resize image in express js

本文关键字:图像 小时 问题 调整 js      更新时间:2023-09-26
 var express = require("express"),
    app = express(),
    formidable = require('formidable'),
    util = require('util'),
    fs   = require('fs-extra'),
    qt   = require('quickthumb');
// Use quickthumb
app.use(qt.static(__dirname + '/'));
app.post('/upload', function (req, res){
  var form = new formidable.IncomingForm();
  form.parse(req, function(err, fields, files) {
    res.writeHead(200, {'content-type': 'text/plain'});
    res.write('received upload:'n'n');
    res.end(util.inspect({fields: fields, files: files}));
  });
  form.on('end', function(fields, files) {
    /* Temporary location of our uploaded file */
    var temp_path = this.openedFiles[0].path;
    /* The file name of the uploaded file */
    var file_name = this.openedFiles[0].name;
    /* Location where we want to copy the uploaded file */
    var new_location = 'uploads/';
    fs.copy(temp_path, new_location + file_name, function(err) {  
      if (err) {
        console.error(err);
      } else {
        console.log("success!")
      }
    });
  });
});
// Show the upload form 
app.get('/', function (req, res){
  res.writeHead(200, {'Content-Type': 'text/html' });
  var form = '<form action="/upload" enctype="multipart/form-data" method="post">Add a title: <input name="title" type="text" /><br><br><input multiple="multiple" name="upload" type="file" /><br><br><input type="submit" value="Upload" /></form>';
  res.end(form); 
}); 
app.listen(8080);

我是节点js和Express js的新鲜人。我关注了这家伙的博客来上传和调整图像大小。以上是代码部分。上传功能正在工作。但是,在调整大小功能方面,如果我想调整上传图像的大小,则出现此错误:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn identify ENOENT
    at exports._errnoException (util.js:746:11)
    at Process._handle.onexit (child_process.js:1053:32)
    at child_process.js:1144:20
    at process._tickCallback (node.js:355:11)

你安装了imagemagick吗?Quickthumb需要它才能工作。