使用multer上传时如何拥有多个文件名

时间:2017-07-02 12:16:02

标签: node.js multer

我的代码如下所示:

bad callback: <function resultCallback at 0x7f1ac4ce6c08>
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 720, in _invoke_callback
    cb(msg)
  File "/root/catkin_ws/src/listen_project/src/node_evaluate.py", line 58, in resultCallback
    jsonFile = json.loads(data.data, 'utf-8')
  File "/usr/lib/python2.7/json/__init__.py", line 351, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

-------------------------------------

在这里,我可以成功上传多张图片,但我无法在上传时获取每个文件的名称。我怎样才能将它们放在const multer = require('multer'); let upload = multer(); let profile_image = ''; const storage = multer.diskStorage({ destination(req, file, callback) { callback(null, './public/images') }, filename(req, file, callback) { profile_image = `${file.fieldname}-${Date.now()}${path.extname(file.originalname)}`; callback(null, profile_image); } }); const userData = (req, res) => { upload = multer({ limits: { fileSize: 1000000, files: 2 }, storage, fileFilter(req, file, callback) { const ext = path.extname(file.originalname); if (ext !== '.png' && ext !== '.jpg' && ext !== '.gif' && ext !== '.jpeg') { return callback(res.end('Only images are allowed'), null) } callback(null, true); } }).any(); upload(req, res, err => { const foodtruck_name = req.body.foodtruck_name; const foodtruck_tag = req.body.foodtruck_tag; console.log(`foodname${foodtruck_name}`); console.log("error" + err); console.log("profile image" + profile_image); if ((!foodtruck_name) || (foodtruck_name.trim() == '')) { console.log("fooddddname " + foodtruck_name); res.json({ status: '404', message: 'Please enter valid foodtruck name' }); } else { const truck = new foodTruck(); truck.foodtruck_name = foodtruck_name, truck.foodtruck_tag = foodtruck_tag, awsUpload.fileUpload(profile_image).then((result) => { truck.foodtruck_img = "https://myWebsite.com/" + profile_image; awsUpload.fileUpload(profile_image).then((result) => { truck.foodtruck_logo = "https://myWebsite.com/" + profile_image; truck.save((err, trucSaved) => { res.json({ status: '200', message: 'Thanks for registering with quflip', data: trucSaved }); }); }).catch((errMsg) => { res.json({ status: '400', message: errMsg }) }); }).catch((errMsg) => { res.json({ status: '400', message: errMsg }) }); } }); }; 函数中?

0 个答案:

没有答案