var express = require('express');
var router = express.Router(),
multer = require('multer');
var uploading = multer({
dest: __dirname + '../public/uploads/',
})
router.post('/upload', uploading, function(req, res) {
console.log('uploaded');
})
我在这里的照片上传教程后出现错误Route.post() requires callback functions
错误。也许这是由新版快递引起的?我记得上面是我们如何把中间放在一条路线上,但为什么在这里它不起作用?
答案 0 :(得分:1)
基于multer docs,您似乎必须使用uploading.single()
或uploading.array()
作为中间件。此示例是从multer docs中的示例用法中获得的:
var upload = multer({ dest: 'uploads/' })
app.post('/profile', upload.single('avatar'), function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
答案 1 :(得分:0)
def grandchild_coins(number_of_grand_children):
# initalizes coins to 1
Coins=1
total_coins=[]
# for grand_child in the range entered this code is ran
for grand_child in range(number_of_grand_children):
# if the grand_child number is not 0 coins = coins*2
if grand_child !=0:
Coins=Coins*2
# prints coins for each grand_child
print ' Grand_Child' + str(grand_child) + str( Coins)
total_coins.append(Coins)
# returns total amount of coins
return sum(total_coins) + ' Coins in total'