2016-07-15 3 views
1
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でより新しくなりました。私はguy's blogの画像をアップロードしてサイズを変更しました。上記はコード部分です。アップロード機能が動作しています。私は、アップロードされた画像のサイズを変更したい場合は、サイズ変更機能の面で、私はこのエラーを得た:エクスプレス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) 

答えて

0

あなたはimagemagickをインストールしましたか? Quickthumbは仕事のためにそれを必要とします。

+0

npm imagemagickを実行した後、私は[email protected] imagemagickを取得しました。私はそれをしたと信じています。 – OtakuFitness

+0

@OtakuFitnessいいえ、それはありませんでした。ドキュメントによると、あなたはimagemagicをutilとしてインストールする必要があります。 Linuxでは 'apt-get imagemagick'をインストールします。あなたが持っているエラーは、 'quickthumb'が' spawn'のためのプログラムを見つけることができないということです。 'imagemagic'のためのラッパーであることを忘れないでください。' imagemagic'自体をインストールする必要があります。 –

+0

https://github.com/zivester/node-quickthumbのドキュメントを読みましたか(そのlibを使用していますか?)たぶんエラーは 'imagemagic'がインストールされていないということです。あなたがPATHに 'imagemagic'とそれをインストールしたことを確認してください。そうでない場合は、修正してください。これがうまくいけない場合は私に知らせてください –

関連する問題