1

伙计们,每当我尝试通过 node.js 上传文件而不使用任何框架时,formidable我都会收到一个错误。所述错误的片段是

 res.write('<div id="capslide_img_cont6" class="ic_container">');
                         res.write('<div class="overlay" style="display:none;"></div><div class="ic_caption">"'+comment[i]+'"</br><div class ="show_addframe" style="display:none;">')
                         res.write('<form method="post" action="/add_new_frame_inputs"><input type="submit" name="add" value="add"/></form>');
                         res.write('<form method="post" action="/change_pic" enctype="multipart/form-data"><input type = "button" value = "Change Pic" onclick=javascript:document.getElementById("imagefile").click();><input type="submit" name="submit"/>');
                         res.write('<input id = "imagefile" type="file" style="visibility: hidden;" name="upload" multiple="multiple"/><input type="hidden" name="id" value="'+id[i]+'"></form></br>');
                         res.write('<form method="post" action="/deletenode"><input type="hidden" name="name" value="'+namet[i]+'"/><input type="submit" name="submit" value="delete"></form></div></div>');
                         res.write('<img src="http://localhost/'+img[i]+'" height="300" width="250"/><br>');
                         res.write('</div></div>');
                         if(i==(namet.length-1)){
                            res.end('</div></body></html>');

此代码处理文件上传并调用此代码

var form    = new formidable.IncomingForm();
                    form.parse( req, function( error, fields, files ){
                      fs.rename(files.upload.path, "/var/www/"+files.upload.name);
                      im.resize({
                      srcPath: "/var/www/" + files.upload.name,
                      dstPath: "/var/www/" + files.upload.name,
                      width:   '500',
                      height: '500'
                        }, function(err, stdout, stderr){
                        if (err) throw err
                        console.log('resized++++')
                            });
                            console.log("Aftr resized");
                      img_path=files.upload.name;
                      pic_tags=fields.pic_tags;
                      var objectid=new ObjectID();
                      pic_id=objectid.toHexString();
                      docname=fields.name;
                      docparent=fields.parent;
                      doccomments=fields.comments;
                      db.frames.update({pic_id:fields.id},{$set:{pic_id:pic_id}},false,true);
                      db.pictures.insert({imgs:img_path,_id:pic_id,pic_tags:null});
                        });
                    console.log("updated frames");
                     res.writeHead(302,{'location':'/main_menu'});
                     res.end();
                        break;  

我得到的错误是这个

 if (err) throw err
                                       ^
Error: Command failed: convert: no decode delegate for this image format `/var/www/' @ error/constitute.c/ReadImage/532.
convert: missing an image filename `/var/www/' @ error/convert.c/ConvertImageCommand/3011.

    at ChildProcess.<anonymous> (/home/r121/Desktop/nilesh/node_modules/imagemagick/imagemagick.js:88:15)
    at ChildProcess.EventEmitter.emit (events.js:91:17)
    at maybeClose (child_process.js:634:16)
    at Process._handle.onexit (child_process.js:676:5)

现在,当我删除im.resize方法时,文件根本不会上传。任何人都可以帮我解决这个问题。感谢 Advance 中的每个人。此外,数据库显示空值。

4

0 回答 0