很抱歉,这可能是一个愚蠢的问题。但是我不明白,如何使用pdfmake
和form-data
npm
包通过表单数据发送pdf文件?
我的代码如下:
const PdfPrinter = require('pdfmake')
const FormData = require('form-data')
const http = require('http')
const printer = new PdfPrinter()
...
async postFile () {
return new Promise((resolve, reject) => {
let docDefinition = { // preparing pdf}
let pdfDoc = printer.createPdfKitDocument(docDefinition)
let form = new FormData()
form.append('file', //WHAT I SHOULD DO HERE?)
form.append('fileName', 'MyFileName')
let request = http.request({
method: 'post',
host: 'my.host.com',
path: '/upload',
headers: form.getHeaders()
})
form.pipe(request)
let result = ''
request.on('response', res => {
res.on('data', chunk => { result += chunk })
res.on('end', () => {
resolve(result)
})
})
request.on('error', err => {
reject(err)
})
})
}
我如何附加以形成我的pdfDoc
或如何pdfDoc.pipe
来形成数据?