javascript - 使用 Node 发送和接收 pdf 文件
问题描述
我正在使用 Express 使用 NodeJs 创建后端服务器。该项目的功能之一是发送和接收 PDF 文件。后端的其他路由发送和接收 JSON 文件,但我想创建一个发送和接收 PDF 文件的路由,我该怎么办?到目前为止我所拥有的:
const express = require('express')
const app = express()
const db = require('./config/db')
const consign = require('consign')
const consts = require('./util/constants')
//const routes = require('./config/routes')
consign()
.include('./src/config/middlewares.js')
.then('./src/api')
.then('./src/config/routes.js') // my routes file
.into(app)
app.db = db // database using knex
app.listen(consts.server_port,()=>{
//console.log('Backend executando...')
console.log(`Backend executing at port: ${consts.server_port}`)
})
app.get('/',(req,res)=>{
res.status(200).send('Primary endpoint')
})
/* basically at routes.js file i'm handling http routes that manages JSON objects such as this one below:
*/
在 routes.js:
// intercept http routes and pass specific funtion for handling them
module.exports =app=>{
app.route('/products')// regular JSON objects
.post(app.src.api.itensVenda.saveItem)
.get(app.src.api.itensVenda.getItems)
.put(app.src.api.itensVenda.toggleItemVisibility)
app.route('/articles')
.get(app.src.api.articles.getArticle)
.post(app.src.api.articles.saveArticle)
// the route above is the one that i want to use for sending and receive PDF files
app.route('/info')// ordinary JSON objects
.post(app.src.api.info.saveInfo)
.get(app.src.api.info.getInfo)
}
解决方案
推荐阅读
- c - 这个 C 代码中的指针发生了什么?
- azure - 机器人频道注册 Cortana MSA
- python - 对角线为矩阵阶数倍数的单位矩阵
- javascript - 连接数组和整数数组的最佳方法
- python - 将字符串中的字符映射到以索引为键的字典中
- python - 如何使用 python docker 模块从容器 ID 获取容器名称
- postgresql - 执行 firewalld 后无法访问 pgAdmin4 服务器模式
- python - 从字符串中删除特定不需要的字符的迭代循环
- ios - 在 Swift 中为 MVVM 模式创建一个可观察的变量
- python - NameError:名称'end'未定义