Estoy teniendo el siguiente error:
(node:12268) [https://github.com/node-fetch/node-fetch/issues/1167] DeprecationWarning: form-data doesn't follow the spec and requires special treatment. Use alternative package (Use `node --trace-deprecation ...` to show where the warning was created) FetchError: request to https://api.nordigen.com/v2/report failed, reason: socket hang up at ClientRequest.<anonymous> (file:///home/doejohn/www/work/johndoe/backend/Scripts/nordigen-scripts/node_modules/node-fetch/src/index.js:108:11) at ClientRequest.emit (node:events:539:35) at TLSSocket.socketCloseListener (node:_http_client:427:11) at TLSSocket.emit (node:events:539:35) at node:net:709:12 at TCP.done (node:_tls_wrap:582:7) { type: 'system', errno: 'ECONNRESET', code: 'ECONNRESET', erroredSysCall: undefined }Cuando hago la siguiente petición:
const data = new FormData(); data.append("input", file); const init = { method: "POST", headers: { Authorization: `Bearer ${oauthToken}`, }, body: data, }; fetch("https://api.nordigen.com/v2/report", init) .then((res) => res.json())Lo tengo funcionando perfectamente con Python. Pero de alguna manera, al convertirlo a Node.js, parece que estoy haciendo algo mal.
resReport = requests.post("https://api.nordigen.com/v2/report", files={'input': open('test2.json', 'rb')}, headers={"Authorization": f"Bearer {token}"})La entrada del archivo en node.js y python es el mismo archivo en el disco. También verifiqué el token de autenticación y es correcto.
Los documentos de la API tienen la siguiente solicitud curl como ejemplo:
curl -X POST \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ -F input=@example.json \ https://api.nordigen.com/v2/report¿Cómo resolver esto?
Agregar lo siguiente resolvió los problemas.
data.append( 'input', fs.createReadStream(`./data/transactions_${process.env.GEBRUIKER}.json`) )