Can't push files from slicer to octoprint using CURL & API

What is the problem?

Hello :slight_smile: I have 2 problems but really only need one solved. Haha. I'm trying to push my sliced gcodes trough the Octoprint API. I'm using this piece of code:

curl -k -H "X-Api-Key: AAAAAAAAAAAAAAAA" -F "select=false" -F "print=false" -F "file=@[output_filepath]" ""

The slicer didn't give any error or anything. Everything seems to be working. But nothing arrives in my octoprint files directory. I used this exact script before and it worked. But I just reinstalled Windows 10 Pro and set everything up. So I guess I am missing something or doing something wrong. I followed the tutorial on github, installed CURL (downloaded the Zip, moved the 2 files into System32, ran Curl from command line to check if its there).

When I manually run the script in CMD I get the following message:

C:\Users\Tronnic>curl -k -H "X-Api-Key: AAAAAAAAAAAA" -F "select=false" -F "print=false" -F "file=@[output_filepath]" ""
curl: (26) couldn't open file "[output_filepath]"

I also installed CURL & my slicer on another machine to see if there is something wrong with my computer, but I have the exact same problem there. Any help on this would be very greatly appreciated.

So since I couldn't get this to work I thought I'll just mount the "watched" folder as an Windows Network Drive. This would solve my problem as well. This worked after some tinkering. I can drag&drop files in there no problem. But when I try to save my gcode from the slicer into the drive I am somehow unable to select it. This is not just from the slicer but also for some other programms I tested with. The connected Networkdrive doesn't show up in the Window. When I manually write the path in the top navigation bar, I get an error saying that the File was not found: (Notice the little "?" on the yellow marked section on the left)

This is what my "Computer" normally looks like:

So I'm out of ideas now. I know its not a big deal to drag and drop a file into the browser. But it was so convenient before to just be able to save the gcode and it would pop up within octoprint. Now I have to save the file, navigate to it, find my octoprint tab next to 20 other tabs and drag it in there.

Any help would be greatly appreciated! Thank you alot :smile:

What did you already try to solve it?
See above

Additional information about your setup
OctoPrint: 1.3.8 (Can't upgrade to 1.3.9 because of TouchUI bug)
Octopi: 0.15.1
Printer: Creality Ender 3
Firmware: Marlin

I was just able to select a file to print using the following to my printer.

curl -k4 --request POST -H 'X-Api-Key: REDACTED' -H 'Content-Type: application/json' --data '{"command":"select","print":false}' http://charming-pascal.local/api/files/local/UnderTop.gcode

How do I place a file there in order to select it?

Ah. So you want to upload it, too.

Here's the documentation example. You'd change out local for sdcard. Remember the data part from before? That now gets replaced with something a lot like their example.

  • The earlier -H content-type header is now something more like this: Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryDeC2E3iWbTv1PwMC. Note that it's your job to assign a unique boundary marker and use it throughout this session; it must begin with at least three hyphens.

  • The data part is now more like this:

Content-Disposition: form-data; name="file"; filename="whistle_v2.gcode"
Content-Type: application/octet-stream

M109 T0 S220.000000
Content-Disposition: form-data; name="select"

Content-Disposition: form-data; name="print"

  • You can make it false as that last part if you don't want to print immediately.

As an alternative to uploading, I formerly would create a Samba share on my uploads folder and just copy in a file that way, then select it from the interface.

I really don't get it. This is somewhat too much for me. Sorry :confused:

All I want is that this works:

It worked before, after a new install of Windows it doesn't work anymore.

I already mounted my Octopi shared folder to my system. But I can't directly save my gcode into it as explained in my first post.

I assume you checked the API and updated the IP address.
Next point could be the Windows Firewall.
Or maybe curl is not proper implemented into windows -> new install.

I switched off Windows Defender & Firewall. Still no success. IP is correct. CURL should be correct as well, it's just dragging those 2 files into system32 right?

Honestly it's been a time I used curl, but I found this. You may can compare.

I just tried ALL available versions of CURL, none worked for me. :frowning:

Like I indicated, I formerly has a Samba share on my OctoPrint's uploads directory.

You then, in Windows, map a drive to this folder. It's then as simple as moving/copying/creating a file in the X:\ folder as before.

Pleaes check out my main post. I even posted pictures that I did this. I just can't directly save into it and I still have to drag&drop files. That's why I wrote "I have 2 problems but only need 1 solved". Maybe you know whats going on there.

I'm not convinced that the error message is truthful. (Sometimes error messages are close to the problem but not actually accurate.) It's indicating that the file was not found but the question mark on the drive mapping implies that there's something wrong with the underlying:

  1. net use
  2. the user associated with the net use
  3. the user or group rights for this user
  4. the default rights mask that was applied to the share point
  5. the ability to browse this drive

Did you read that Samba step-by-step tutorial which I wrote (and linked earlier)? There are quite a few little things which—if absent—will mean that this won't work. For reasons which are beyond me, the Samba (or perhaps the underlying SMB protocol) require you to indicate many times that you wish this to be a writeable share.

Comment=Pi share to the microSD share folder
Read only=no
only guest=no
create mask=0777
directory mask=0777
Guest ok=yes

Note that you must add an SMB user for this. SMB requires that the UNIX pi user be added to their own group to allow this to function.

# When prompted, enter "raspberry" for the password for this to
# set the password used by Windows share users
sudo smbpasswd -a pi

It's always good to parse the configuration file to make sure that there isn't a bug.

sudo testparm /etc/samba/smb.conf

When mapping the drive, you need to be the (SMB-based) pi user and to use the NETBIOS name of the Raspberry rather than its hostname:

net use p: \\octopi\microsd /user:pi raspberry

I sent you an PM showing my problem in a short video. :slight_smile:

Okay, wow. I guess I found a temporary fix. Haha. Im genius! :rofl: just kidding :sweat_smile:

In my slicers post processing settings / additional terminal commands, I'll run this:

winscp /script="F:\3D Files\Stuff\movescript\movegcodescript.txt"

Contents of "movegcodescript.txt"

option echo off
option batch on
option confirm off
open sftp://pi:PASSWORD_OF_PI@
lcd "F:\3D Files\GCode"
put -nopermissions -nopreservetime -delete "*.*"


This was too easy. But it was hard to get the idea.
It might also be very useful for people using a slicer that doesn't support running something after slicing. Simply place a shortcut to the a .bat file containing the following after slicing:

@echo off
winscp /script="P:\ATH\TO\THE\SCRIPT.txt"

During WinSCP installation, this box has to be ticked

By the way, I was able to use CURL from the windows command line. It worked. I don't know why it doesnt in my slicer...
Output of CMD:

C:\Users\Tronnic>curl -k -H "X-Api-Key: MYOCTOPRINTAPIKEY" -F "select=false" -F "print=false" -F "file=@F:\3D Files\GCode\Rolladen-halter.gcode" ""
  "done": true,
  "files": {
    "local": {
      "name": "Rolladen-halter.gcode",
      "origin": "local",
      "path": "Rolladen-halter.gcode",
      "refs": {
        "download": "",
        "resource": ""

All this freaking work for a 5 second timesave when saving gcode. What do I do with my life. :stuck_out_tongue_closed_eyes:


You're an inspiration to others. Good job.


Just curious, what slicer are you using, don't think I ever saw that in the posts? I ask because the more recent versions of Slic3r and Slic3r Prusa Edition include OctoPrint uploading natviely in the General section of Printer Settings.


1 Like

And there is a solution for S3D too.
And for Cura.
And for Kisslicer.

Good, I also had problems with CURL, I was going to implement the use of WINSCP and Swish, but I really wanted to use CURL, I investigated a little and I ended up solving it, it seems that the problem was not using the [output_filepath] syntax, I tried several combinations of [output_filepath] and [output_filename] but without success. I ended up finding that just using [output_filepath] I had everything we needed.