使用python请求将文件上传到Nodejs [英] Upload a file to Nodejs using python request
本文介绍了使用python请求将文件上传到Nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在nodejs方面获得了一些帮助:从POST请求nodejs中提取文件
I got some help here on the nodejs side: Extract file from POST request nodejs
我是Node的新手,获取此文件时遇到问题 node.js(服务器PC)
I am new to node, and I am having problems getting this file node.js (Server 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)
python script (Client PC)
files = {'file': ('test_file', open(filePath, 'rb'))}
r = requests.post("http://192.168.2.39:3000/upload", files=files)
我在这里做错了什么?谢谢
What am I doing wrong here? thanks
我遇到错误500,
意外字段
I am getting error 500,
Unexpected field
Error: Unexpected field
at makeError (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\lib\make-error.js:12:13)
at wrappedFileFilter (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\index.js:40:19)
at Busboy.<anonymous> (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\multer\lib\make-middleware.js:114:7)
at emitMany (events.js:127:13)
at Busboy.emit (events.js:201:7)
at Busboy.emit (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\busboy\lib\main.js:38:33)
at PartStream.<anonymous> (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\busboy\lib\types\multipart.js:213:13)
at emitOne (events.js:96:13)
at PartStream.emit (events.js:188:7)
at HeaderParser.<anonymous> (C:\qa\Automation\MyProj\Python Automation\Utilities\node\MyProjrtu\node_modules\dicer\lib\Dicer.js:51:16)
推荐答案
在node.js中更改
upload.array()
到
upload.array('file')
in node.js change
upload.array()
to
upload.array('file')
和在python中:
files = {'file': ('test_file', open(filePath, 'rb'))}
至
files = {'file':open(filepath,'rb')}
检查此帖子的答案获取从节点中的帖子发送的图像. js
这篇关于使用python请求将文件上传到Nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文