From 407627ef6a5a62be4fc67bc12c1c6aa550c88f36 Mon Sep 17 00:00:00 2001 From: Chrystian Huot Date: Thu, 4 Jul 2019 09:33:48 -0400 Subject: [PATCH] Fix upload API in regards to url-encoding the audio stream --- server/imports/api/upload.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/imports/api/upload.ts b/server/imports/api/upload.ts index 05bb114..11ad21c 100644 --- a/server/imports/api/upload.ts +++ b/server/imports/api/upload.ts @@ -10,7 +10,7 @@ if (Meteor.isServer) { if (req.method === 'POST') { const form = new Form(); - let audio = 'data:audio/mpeg;base64,'; + let audio = ''; let json = ''; let key = ''; let system = ''; @@ -19,10 +19,10 @@ if (Meteor.isServer) { part.on('data', (data) => { switch (part.name.toLowerCase()) { case 'audio': - audio += data.toString('base64'); + audio += data.toString('binary'); break; case 'json': - json += data.toString('binary'); + json += data.toString('utf8'); break; case 'key': key += data.toString('utf8'); @@ -40,6 +40,8 @@ if (Meteor.isServer) { const apiKeys = Meteor.settings.apiKeys; if (key && Array.isArray(apiKeys) && apiKeys.find((apiKey) => apiKey === key)) { + audio = 'data:audio/mpeg;base64,' + Buffer.from(audio, 'binary').toString('base64'); + try { const call = new Call(Object.assign({}, JSON.parse(json), { audio, system })); @@ -57,7 +59,6 @@ if (Meteor.isServer) { res.writeHead(403); res.end('wrong or no api key provided'); } - })); form.parse(req);