gpt4 book ai didi

javascript - 在 Express JS 中上传和调整图像大小时遇到​​问题

转载 作者:太空宇宙 更新时间:2023-11-03 22:30:05 25 4
gpt4 key购买 nike

 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);

我是 Node js 和 Express JS 的新手。我关注了这个guy's blog上传并调整图像大小。以上是代码部分。上传功能正在运行。但是,在调整大小功能方面,如果我想调整上传的图像大小,则会出现此错误:

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吗? Quickthum 需要它来工作。

关于javascript - 在 Express JS 中上传和调整图像大小时遇到​​问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38387581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com