在快速 js 中上传和调整图像大小时出现问题
Got issue with upload and resize image in express js
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需要它才能工作。
相关文章:
- 如何在调整浏览器大小时将图像保持在适当位置
- 加载/调整大小时未切换图像数据标记
- 调整大小时移动在高图表上呈现的图像
- 使用年、月、日期、小时、秒格式每分钟刷新一次图像
- 使用jQuery对图像进行居中和动态调整大小时出现问题
- 调整窗口大小时,页面上的四个图像将不会调整大小
- 如何在滚动/调整大小时保持背景图像覆盖屏幕
- 如何在调整窗口大小时流畅图像
- 缩放图像,而不是在调整浏览器窗口大小时环绕图像
- 谷歌地图首先加载灰色,当调整大小时加载图像
- 如何在 d3.js 中调整图像大小时不保留纵横比
- Javascript时钟用图像更改小时,分钟,秒
- 如何在屏幕变小时使图像成为链接
- 如何使用jQuery重新加载'srcset'调整浏览器大小时的图像
- 调整浏览器窗口大小时,图像不会调整大小(elm)
- 当调整另一个图像的大小时,KineticJS会重新计算图像的位置
- setInterval()是如何工作的?我可以用它每小时更换一次图像吗
- 当主图像调整大小时,使顶部图像保持原位
- 调整浏览器大小时,图像上方的文本不起作用
- 当浏览器宽度减小时,减小图像宽度