How to upload byte array of .gcode file to OctoPrint?

What is the problem?
Hello, I want to upload byte array to octoprint. I am using c#. I have downloaded file from octoprint and saved it to byte array and now I want to upload this byte array with file to printer. Please, how can I do it?

What did you already try to solve it?

I have already tried this:

What happened? Did you get an error with that code?

The endpoint seems wrong.
You want EndPoint + "api/files/local" instead of trying to log in.
https://docs.octoprint.org/en/master/api/files.html#upload-file-or-create-folder

1 Like

Yes, thank you. I copied my code from login and frogot to edit it. I edit it, but it still do not work. Error 400 - bad request

It return 0, because it crash in try-catch and if I remove try-catch it will return 400 - bad request

I suggest to read the API docs that @fieldofview so kindly linked you. If you follow them your requests will no longer be malformed and your upload might actually succeed.

Okay, but I don't know how to upload it from c# it is not written in API. Is this method right and only y upload data model is bad?

I don't speak C#, but your request is missing required parts, such as the filename of the gcode file to write.

Your code is incorrect, the API works, for many people.