【问题标题】:Upload a file to Nodejs using python request使用 python 请求将文件上传到 Nodejs
【发布时间】:2017-09-02 03:23:45
【问题描述】:

我在 nodejs 方面得到了一些帮助:Extract file from POST request nodejs

我是 node 新手,在获取此文件时遇到问题 node.js(服务器PC)

var express = require('express');
var bodyParser = require('body-parser');
var multer = require('multer')

var app = express();
var upload = multer({ dest: 'uploads/' })

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

/* POST commands */
app.post('/upload', upload.array(), function (req, res, next) {
console.log("I AM HERE");
})

python 脚本(客户端 PC)

files = {'file': ('test_file', open(filePath, 'rb'))}
r = requests.post("http://192.168.2.39:3000/upload", files=files)

我在这里做错了什么?谢谢

我收到错误 500,

意外字段

错误:意外的字段
    在 makeError (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\lib\make-error.js:12:13)
    在 WrappedFileFilter (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\index.js:40:19)
    在 Busboy. (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\lib\make-middleware.js:114:7)
    在 emitMany (events.js:127:13)
    在 Busboy.emit (events.js:201:7)
    在 Busboy.emit (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\busboy\lib\main.js:38:33)
    在 PartStream. (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\busboy\lib\types\multipart.js:213:13)
    在 emitOne (events.js:96:13)
    在 PartStream.emit (events.js:188:7)
    在 HeaderParser. (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\dicer\lib\Dicer.js:51:16)

【问题讨论】:

标签: python node.js file upload


【解决方案1】:

在 node.js 中更改 upload.array()upload.array('file')

在python中:

files = {'file': ('test_file', open(filePath, 'rb'))}

files = {'file':open(filepath,'rb')}

查看这篇帖子Get image sent from post in node.js的答案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-10
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 2017-10-11
    • 2019-05-20
    相关资源
    最近更新 更多