Ugh, sorry, you’re completely correct. It should be an array. However, afterwards I can upload data as long as you set the content type to application/octet-stream
. Here’s an example where I patch the string out for the array in your file:
const crypto = require('crypto');
const fs = require('fs');
let buffer = fs.readFileSync('/Users/janjongboom/Downloads/encoded.cbor');
const request = require('request');
// patch buffer from string => array
let valuesSearchFor = Buffer.from('6E5265662D42494E4152592D693136', 'hex');
let valuesSectionIx = buffer.indexOf(valuesSearchFor);
console.log('index', valuesSectionIx);
buffer = Buffer.concat([
buffer.slice(0, valuesSectionIx),
Buffer.from('9F6E5265662D42494E4152592D693136FF', 'hex'),
buffer.slice(valuesSectionIx + valuesSearchFor.length)
]);
// fs.writeFileSync('/Users/janjongboom/Downloads/encoded.fixed.cbor', buffer);
// now upload the buffer to Edge Impulse
request.post('https://ingestion.edgeimpulse.com/api/training/data', {
headers: {
'x-api-key': 'ei_...',
'x-file-name': 'test01',
'x-label': 'test',
'Content-Type': 'application/octet-stream'
},
body: buffer,
encoding: 'binary'
}, function (err, response, body) {
if (err) return console.error('Request failed', err);
console.log('Uploaded file to Edge Impulse', response.statusCode, body);
});
One thing that might go wrong here is that we expect the values array to be an indefinite length array (so we can abuse the 0xFF
termination of the CBOR header). That might have gone amiss in your code. I’ll try and document this better (I’m pretty sure you’re the first external person to implement this part of the protocol). (edit: I see that that part was already in the docs, but I’ve added the Content-Type section).