我正在尝试将CSV文件从python上传到基于Express的Nodejs服务器,以下分别是代码
Python上传CSV
import requests
url = "http://localhost:8000/cs/api/v1/messages/bulk_csv"
payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"csvfile\"\r\n\r\n\r\n-----011000010111000001101001--\r\n"
headers = {
'Content-Type': 'multipart/form-data',
}
file = open('Low.csv', 'rb')
files = {"files": file}
response = requests.request("POST", url=url, files=files, headers=headers)
Nodejs快速路线
static async postBulkMessagesFromCSV(req, res) {
const csvData = req.files.csvfile.data.toString('utf8');
}
问题是req.files始终为null。有没有办法从python正确发送csv,以便我可以访问node.js中的req.files?