Thank you for the help. With this information, I have made a lot of progress.
I can now download, assemble and save an .epe
file (once I figured out LZString.decompressFromUint8Array and base64 encoding the preview jpg).
I can also download the binary file representation of the pattern by downloading http://<ip>/p/<pattern_id>
What I am having real trouble with is re-uploading the saved binary file.
The specific part I have a problem with is in putProgramBinary
:
form.append('data', binary, {
filepath: '/p/' + programId,
contentType: 'application/octet-stream',
});
I’m not a javascript programmer, and I don’t know what the third parameter is supposed to represent (references say filename
, but it isn’t a filename).
I’m programming in python, and I have tried this:
async def load_binary_file(self, filename=None, binary=None):
try:
if not binary:
if not filename: return
with open(filename, 'rb') as f:
binary = f.read()
programId = filename.replace('.bin','')
data = aiohttp.FormData()
data.add_field('data',
binary,
filename = '/p/' + programId,
content_type='application/octet-stream')
async with aiohttp.ClientSession() as session:
async with session.post('http://{}/edit'.format(self.ip), data=data) as resp:
self.log.info(resp.status)
await resp.text()
if resp.status == 200:
self.log.info('file: {} loaded'.format(filename))
except Exception as e:
self.log.exception(e)
Which gives me a 200 response, but no pattern is loaded on the pb.
Any idea where I am going wrong? is the whole post supposed to be application/octet-stream
? in which case I need to convert everything to bytes.
if I could understand the javascript FormData(), I’m sure I could figure it out.
Thanks.