如何将XML文件从PUG发送到节点JS
您好,我正在构建一个应用程序,其中您可以上传XML文件并将其发送到API。我正在使用express和nodejs。我是新手。我在帕格(Pug)上创建了上传和发送按钮,并在节点上接收一个函数。前端和后端在同一端口上运行。如何将XML文件发送到后端以阅读并将其发送到API?
这是我的代码:
pug:
doctype html
html(lang='en')
head
title Transport
body
h3 Upload XML:
form(method='post', enctype='multipart/form-data' action='/upload')
input(type='file', name='xml')
br
input(type='submit', name='xml', value='Upload XML')
app.js file:
const express = require('express')
const app = express()
app.set('view engine', 'pug')
app.set('views', './src/views')
app.get('/', (req,res) => {
res.render('index')
});
app.get('/upload', (req,res) => {
})
app.listen(3000, () => console.log("Listening on port 3000"))
这是我使用节点和哈巴狗构建的第一个应用程序,这就是为什么我问这个简单的问题。
Hello I am building an app in which you upload an xml file and send it to an api. I am using Pug and NodeJS with Express. I am new to this. I created in pug the upload and send button and a function to receive on node the file. The frontend and backend are running on the same port. How can I send the xml file to the backend to read it and send it to the api ?
This is my code:
Pug:
doctype html
html(lang='en')
head
title Transport
body
h3 Upload XML:
form(method='post', enctype='multipart/form-data' action='/upload')
input(type='file', name='xml')
br
input(type='submit', name='xml', value='Upload XML')
app.js file:
const express = require('express')
const app = express()
app.set('view engine', 'pug')
app.set('views', './src/views')
app.get('/', (req,res) => {
res.render('index')
});
app.get('/upload', (req,res) => {
})
app.listen(3000, () => console.log("Listening on port 3000"))
It is my first app built with node and pug and this is why I am asking this easy question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改
get
发布
,然后您的文件将在req.files
属性中change
GET
toPOST
and then your files will be inreq.files
property您的方法是不匹配的。 '/upload',(req,res)=> {})方法
your method is mismatch.you should change your
app.get('/upload', (req,res) => {})
method in app.js file toapp.post('/upload', (req,res) => { })
method