2011-12-12 44 views
0

我已经做了一个上传功能,并使用强大的连接形式和https://github.com/ctavan/express-validator。我正在尝试清理xss中的图像。但我得到TypeError: Cannot call method 'replace' of undefined。那么我在哪里获得实际图像进行消毒?Expressjs express-validator清理xss图像

app.post('/upload', function(req, res, next){ 

    req.form.complete(function(err, fields, files) { 

     if (err) { 
      console.log(err); 
     } 
     else { 

      //------>Sanitize image from xss?? 
      req.sanitize(?).xss(true); 

      res.send('/images/users/' + files.file.filename); 
     } 
    }); 
}); 
+0

你实际使用''req.sanitize带问号的存在或者是副本错字(?) ? – seppo0010

+0

不,没有错别字。我一直在试图让那里的形象。问号在那里指出,我不知道该把什么放在这里。 – georgesamper

回答

0

你应该使用:

var image = req.sanitize('image_field_name').xss(true); 

而不是:

var image = req.sanitize(value_of_image_from_form).xss(true); 
+0

它仍然相同,得到相同的错误信息'不能调用方法'取代'未定义'。似乎无法找到一种方法来定位图像... – georgesamper

+0

好吧 - 我再次检查它,并且当req.body [image_field_name]未定义时,它似乎会抛出此错误,因此您应该检查表单值,例如 'var val = req.body [image_field_name] || '';' –