Best practice for file handling on upload (including changing files) via plugin hook


I maintaining the Slicer Estimator plugin and like to discuss an implementation for changing the GCODE files still uploaded. I remember that this should be done on upload with LineProcessorStream only. Is that right or can I change files later to e.g. update all files if the plugin is installed later without causing other problems?

Adding lines during upload...


You can do it outside of file upload. I created a scanner in slicer thumbnails plugin settings to process all uploaded files to extract missing thumbnails.

Will it run into problems like wrong file size? Is there something to avoid like changing files not during printing? The scanner does read the files only if I am correct? Take a look into the project some years ago during the first steps.

Most plugins like DisplayLayerProgress do not allow processing files after the upload I am uncertain if I should spend time into this.

It's not common to modify after upload. Yes, my plugin only reads the file, but that doesn't prevent you from modifying a file. I've heard people mention of even using gcode editor plugin while printing the file, but I personally would never try to process/alter a file while printing, especially the file that was printing. At some point DLP plugin was actually processing on select and not upload.

Ok, so changing uploaded files is not permitted. It would make it easier for users to avoid uploading everything again that's why I planning that feature.

Its funny, I implemented it 2 days ago that some updates that do not need changing the GCODE file are executed if somebody selected it. :slight_smile: So I will add changing the file there also and an update for all files as special function in plugin settings. I did not look for my self (I will) but do you know if it is possible to block printing during an overall update to avoid printing files that are actually updating? I will block the GUI if an update is running but I do not know if printing could be started via API during this phase.

That's not what I said. There are plugins that do just that like gcode editor plugin.Maybe if you explained what you were trying to change it would make more sense to me what you are trying to do.

I don't know if that's possible, maybe with octoprint.server.api.before_request hook. Only example plugin I can think of using that right now is PSU Control for file uploads, I would think maybe starting a print would be the same.

Yes, was a typo. Wanted to write "not forbidden". :slight_smile:

I like to add "@TIME_LEFT 123" commands to get it back during printing. Not real GCODEs that are send to the printer. I need it as a marker to get the printtime remaining. This will be added during upload and I like to add a function to loop every file missing this information and add it without uploading it again. This is helpful if my plugin is installed later...