I need help. Error uploading .gcode

nice to meet you.

An error occurs when trying to upload a gcode file using a Javascript client.
Anyone know how to make it work?

I'm trying with the code below but it doesn't work.

var element = document.createElement('input');
element.name = 'myFile';
element.type = 'file';
element.addEventListener('change', function(e){
var result = e.target.files[0];
var reader = new FileReader();
reader.addEventListener('load', function(){
client.files.upload('local', reader.result, {filename: 'hogehoge.gcode'});

In a cross origin context (= "not hosted within OctoPrint") you need to enable CORS support within OctoPrint and use an API key. In a same origin context you need to implement the CSRF token.


What you are showing there is basically what constitutes a CSRF attack and OctoPrint protects against that.

I will try again after studying CSRF thoroughly.
Thank you for your teachings.