Jump to content
korny86

POST print_job with nodeJS

Recommended Posts

Posted · POST print_job with nodeJS

Hello,

I try to start a print job over the API of my Ultimaker 3. I read the example in this post

 and tried to port the code from python to nodeJS, but the POST request is just hanging.

 

Code:

var request = require("request");
var fs = require('fs');
  
var formData = {
    "file": {
      value: fs.createReadStream('C:\\Users\\efentzahn\\IKIMUNI_Schornstein_simple2.gcode'),
      options: {
        filename: 'IKIMUNI_Schornstein_simple2.gcode'
      }
    }
};

request.post( {url: 'http://10.53.1.114/api/v1/print_job',
              auth: { user: '45fa38b52ea5a998c085145930356bd6', pass: '63bb0fc18a39ba7c787805e80f0be1211144f4083de634deb57f7e7819a640ec', sendImmediately: false},
              formData: formData},
function(error, response, body){
    if (!error && response.statusCode == 201){
        console.log("Print started.");
    }
    else{
        console.log('Code : ' + response.statusCode)
        console.log('error : ' + error)
        console.log('body : ' + body);
    }
});

 

The auth is working. It must be a problem with the formData. Have anyone tried this with nodeJS until now?

Share this post


Link to post
Share on other sites
Posted · POST print_job with nodeJS

It's been a while since I developed anything in Node, but in general the code looks ok.

 

How long have you waited? Maybe you're trying to post a very big file?

 

As a first thing, I would try doing an /api/v1/auth/verify request. Just as a sanity check to test if you are correctly submitting the username and password.

 

If that is working, maybe you can try some of the easier calls that don't need a multipart form, like setting the LED brightness?

 

Otherwise, you may need to check your multipart form code. I know this can be complicated in many languages and it looks like the syntax is ok, but you never know.

(I used Google to find this: https://github.com/request/request#multipartform-data-multipart-form-uploads )

Share this post


Link to post
Share on other sites
Posted · POST print_job with nodeJS

The login is working and doing PUT request like pause a print works fine in node.js.

The file is 340kbyte "big". That should be transmitted very fast. After a few seconds (maybe 10?) node ends with the error: "socket hang up".

 

I think the problem is the multipart form part, but i have no clue what it is exactly. I already googled a lot and the code posted above is developed with this example from the request library. But the correct names and needed fields in the multipart form is dependent to the Ultimaker API. So, I have the strong feeling that a Ultimaker developer have to take a look at the code.

Share this post


Link to post
Share on other sites
Posted · POST print_job with nodeJS

Hi everybody ! Any update on this one? i'm facing the same result on nodejs.

 

Moreover : 

I tried with multiple tools : 

- Insomnia : works as expected -> It's possible to start a print job

- Curl command line : works as expected -> It's possible to start a print job

- Post Man : Cannot make it work ( error code : 400 Bad request :  "message": "No file received")

- Python3 : same as PostMan ( the file seems to be received by the printer as i see message in printer's log : (but seems empty?)

 

Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[450]: 2019-02-12 10:58:10,096 INFO     printJob        Saving received file UM3_MusicNoteKeyChainXL.gcode",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[450]: 2019-02-12 10:58:10,118 INFO     printJob        File saved as /tmp/UM3_MusicNoteKeyChainXL.gcode",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: 2019-02-12 10:58:10,125 INFO     controller      Request to start procedure: PRINT",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: 2019-02-12 10:58:10,130 ERROR    controller      Exception in procedure start",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: Traceback (most recent call last):",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: File \"/usr/share/griffin/griffin/printer/controller.py\", line 455, in startProcedure",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: if not procedure.setup(parameters):",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: File \"/usr/share/griffin/griffin/printer/procedures/print/printProcedure.py\", line 102, in setup",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: self._parse_header_step.getFileHandler().cleanup()",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: AttributeError: 'NoneType' object has no attribute 'cleanup'",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[450]: 2019-02-12 10:58:10,137 WARNING  printJob        Print of UM3_MusicNoteKeyChainXL could not be started"

 

All others API ( led, blink, message... ) are working well with digest auth but this one ( maybe because of the multipart/form-data aspect) is not working consistently for me.

 

Can anyone provide support on handling Print_job api from a webapp (nodejs / python? ) / or a working code?

 

thanks

Share this post


Link to post
Share on other sites
Posted · POST print_job with nodeJS

Hello,

I moved to python3 and here is my working code:

    def StartPrint(parent, file):
        logger.info("Start print job. File: ")
        logger.info(file)
        
        if os.path.exists(file):
            jobname = os.path.basename(file)
            filepath = file
            logger.debug(jobname)
            # Start a print 
            r = requests.post('http://10.10.109.40/api/v1/print_job', auth=requests.auth.HTTPDigestAuth('45fa38b52ea5a998c085145930356bd6', '63bb0fc18a39ba7c787805e80f0be1211144f4083de634deb57f7e7819a640ec'), files={"file": (jobname, open(filepath, "rb"))} )
            logger.info(r.status_code)
        
            if r.status_code == 201:
                return True
            else:
                return False
        else:
          logger.info("File doesn't exist!")
          return False

You have to change the IP and auth data to your device.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Our picks

    • Ultimaker Cura | a new interface
      We're not only trying to always make Ultimaker Cura better with the usual new features and improvements we build, but we're also trying to make it more pleasant to operate. The interface was the focus for the upcoming release, from which we would already like to present you the first glance. 
        • Like
      • 181 replies
    • "Back To The Future" using Generative Design & Investment Casting
      Designing for light-weight parts is becoming more important, and I’m a firm believer in the need to produce lighter weight, less over-engineered parts for the future. This is for sustainability reasons because we need to be using less raw materials and, in things like transportation, it impacts the energy usage of the product during it’s service life.
        • Like
      • 12 replies
×
×
  • Create New...

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!