From her own example, this appears to be a POST'd session. Note the multipart-MIME decorations throughout. You might want to just toggle those two booleans to FALSE, though.
If we just don't look at the JS for a second and try to solve the Postman-issue, I'm sure it'll help me understand what I'm doing wrong in javascript (and Postman can generate the request code for just about any language)
From what I believe to be the correct post-format in Postman, it'd be this code in cURL;
I'm glad you found your solution @AlbertMN for the file uploads. I hope this and the plugin tweaks we did gets your school printer farm working as you were hoping to. Just out of curiosity, what was the server side you were integrating the API with for managing the printers?
No, if this was the case it would've told me. The postman request still doesn't work, so I'm suspecting there's a problem with it - it might be due to the fact that Im using the old chrome app - it didn't seem to actually send the file, just the file name. I generated the code from Postman and replaced the name with the actual file, and it worked.
@jneilliii the server side is for user tracking before a student uses the printer, they have to enter their name, grade/class and optionally an email address where they can be mailed when the print finishes, gets cancelled or fails. Furthermore we use it for filament tracking - we give each roll an ID, how much plastic it contains and then updates how much is left. This way we can stop the user automatically if the printer doesn't have enough filament to finish their print. To change filament, you simply press a button, it heats up the extruder, releases the PLA and instructs them how to put in a new one
So all together a system that is as idiot-proof as possible!
I do love Postman and I teach it to my students (I work at a software development bootcamp). There are times, though, when it (silently) makes things too easy. It might work in Postman and not work in curl and then I'm left to wonder what secret help it just did to make this work. Unfortunately, I can't then "take that into JavaScript" for the ultimate solution.
Oh and since you do JavaScript, you might try my octo-client sometime. But of course, it's Node-based.
var OctoPrint = require('octo-client');
OctoPrint.printerState(function(ptr){
if (ptr.state.flags.operational) {
var targetHotend1 = ptr.temperature.tool0.target;
console.log(targetHotend1);
}
});
@OutsourcedGuru, what's the benefit of your client over the stock one? I'm not really familiar with node.js and it's benefits so maybe that's the main difference. There is mention on the stock js client linked above about instantiating multiple instances, which would serve as a good example I think.
@jneilliii Here's an example of some small CLI programs which I've written myself from my own octo-client:
octo-temp
#!/usr/bin/env node
var OctoPrint = require('octo-client');
OctoPrint.printerState(function(response){
if (response) {
if (response.temperature) {
if (response.temperature.tool0) {
var t = response.temperature.tool0;
console.log('The first hotend is set to ' +
t.target.toString() +
'C and is currently ' +
t.actual.toString() + 'C.')
};
};
};
});
Creating that in Node, adding a symlink so that it's in your path and you could then just run:
$ octo-temps
The first hotend is set to 190C and is currently 182.5C.
You could both query the printer's state and then do different things as a result. I've created web services which do this on the backend since Node's good for that. I've even added Node to my OctoPrint installation so that I can run additional services there. I've got one listening to port 3000 which acts as a simple proxy; it's just easier than creating a plugin (at least if you're me).
I've got some which query on behalf of the Conky TFT interface to gather logistics.
Node.js is based upon the Chrome V8 JavaScript engine. It's got a superb asynchronous queuing mechanism which scales up to mondo levels. It's hardcore stuff and it is well-positioned to replace Java, .NET and even C/C++ (eventually).
I'm trying to upload file to a specific folder using the curl command, how exactly do I specify the folders location when it's next under the local upload location?
That last argument would need to change. "local" just means "the root of the local uploads folder". Just add more path onto that like http://octopi.local/api/files/local/subdirectory.
Does the folder exist already (and you created it using the Files side panel widget)?
Is there a hidden .metadata.json file in that folder and are the contents reasonable? For example, cat ~/.octoprint/uploads/subdirectory/.metadata.json
Have you tried first just uploading to the root folder of uploads using the first example and did that succeed?
Did you replace MYOCTOPRINTAPIKEY with your actual key from Settings -> API?
Since I keep getting requests on this subject, here is a quick-and-dirty HTML/JavaScript (mostly) client-side attempt at pushing a file to OctoPrint without needing NodeJS or any modules for that.
For my browser at least, it won't allow cross-origin requests if I'm trying to use the file protocol; it must be http or https. So the page below must be served somehow. I've used serve-static as I recall and installed this globally on my computer using npm. The CLI is then called serve and you'd run this in the folder in question. It will then simply serve the index.html page on http://localhost:3000/, satisfying the cross-origin safety check.
This works for Postman and NodeJS using Axios. Thank you for simplifying it. I was trying to use all the requested parameters on the API documentation and it just kept giving me 400 responses. Truly, thank you.
Using the OctoPrint API with Postman to upload a file to OctoPrint (Octopi)