Axios을 통해 Google API로 PDF를 보내려고하는데 문제가 있습니다.서버 (NodeJs)의 axios를 통해 google API로 보내기
코드 나는 시도 :
const express = require('express');
const axios = require('axios');
const router = express.Router();
const PDFDocument = require('pdfkit');
const ticketProperties = {
'version': '1.0',
'print': {}
};
router.post('/print/sale', async (req, res) => {
// Generate test PDF
let doc = new PDFDocument;
doc.pipe(fs.createWriteStream('output.pdf'));
doc.fontSize(8)
.text('Some text example for pdf', 1, 1);
doc.end();
// Once the pdf is generated, read it and send it via axios
axios.post(
'https://www.google.com/cloudprint/submit',
{
printerid : 'PRINTER_ID_REMOVED_INTENTIONALLY',
title: 'pdf print',
ticket: ticketProperties,
content : doc,
contentType: 'application/pdf'
},
{
headers: {
'Authorization': 'Bearer ACCESS_TOKEN_REMOVED_INTENTIONALLY',
'Content-Type': 'application/pdf'
}
}
)
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
});
내가console.log(error)
에있어 오류 난 그 API를 호출
TypeError: Converting circular structure to JSON at JSON.stringify() at transformRequest (G:\projects\pos-web\pos-backend\node_modules\axios\lib\defaults.js:51:19) at transform (G:\projects\pos-web\pos-backend\node_modules\axios\lib\core\transformData.js:16:12) at Object.forEach (G:\projects\pos-web\pos-backend\node_modules\axios\lib\utils.js:224:12) at transformData (G:\projects\pos-web\pos-backend\node_modules\axios\lib\core\transformData.js:15:9) at dispatchRequest (G:\projects\pos-web\pos-backend\node_modules\axios\lib\core\dispatchRequest.js:37:17) at
내가 파일을 쓰고 있어요 때문 오류가 생각 게시물의 몸 안에 doc
. 전에 처리해야합니까?
노트 :
- PDF를 내 프로젝트의 내부에 성공적으로 생성됩니다.
- 첫 번째 테스트는 pdf 대신 텍스트를 보내고 OK입니다.
- 나는 많은 가능한 해결책을 시도했지만, 나에게 다른 오류를 주었다. 어쩌면 서버에서 pdf를 보내는 방법을 잘못 이해하고있을 수도있다. 하시기 바랍니다 Axios 대신에 다른 라이브러리가 있거나 서버에서 pdf를 보내는 방법의 흐름을 알고 있다면 주저하지 말고 답변으로 보내십시오.
더 많은 정보 : 엔드 포인트 https://www.google.com/cloudprint/submit
에 대한
- : Link