Send a file with multipart/form-data to OctoPrint REST API

@knolleary: thanks for confirming it, I have tried POSTing a multipart with some JSON metadata first and then a filebuffer using the structure described

{
    "KEY": {
        "value": FILE_CONTENTS,
        "options": {
            "filename": "FILENAME"
        }
    }
}

as described.

My msg.headers are set to:

{
   "Content-Type":"multipart/form-data",
   "Accept":"application/json",
   "Authorization":"Bearer "
}

My payload are structured like this (values mocked up for data-protection):

{
    "CaseID":1234567890,
    "DocumentName":"Testing .pdf POST",
    "Casepart":{
                         "PartId":12345,
                         "PartType":"Person"
                       },
     "Documenttype":
                   {
                        "Id":1,
                        "Name":"TestName"
                    },
   "Beskrivelse":"Test",
   "file":{
               "value": [37,_values left out for readability_,80],
               "options": {
                                  "filename":
                                  "test.pdf"}
                                }
}

The reply i get from the endpoint though is ""Object reference not set to an instance of an object." which indicates that one of my values is empty or malformed or maybe that the endpoint cannot recieve the data in this format..

Heres my flow with sensistive data removed:

[{"id":"e39491ff.49538","type":"pdfmake","z":"f08e748.bb67888","name":"","outputType":"Buffer","inputProperty":"payload","options":"{}","outputProperty":"filebuffer","x":280,"y":60,"wires":[["f20736f5.799d08","88e8a48f.723278"]]},{"id":"d8ae17d6.85ee48","type":"inject","z":"f08e748.bb67888","name":"Test Data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"content\":[\"First paragraph\",\"Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines\"]}","payloadType":"json","x":100,"y":60,"wires":[["e39491ff.49538"]]},{"id":"f20736f5.799d08","type":"debug","z":"f08e748.bb67888","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"filebuffer","targetType":"msg","statusVal":"","statusType":"auto","x":360,"y":120,"wires":[]},{"id":"88e8a48f.723278","type":"change","z":"f08e748.bb67888","name":"request parametre","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"Content-Type\":\"multipart/form-data\",\"Accept\":\"application/json\",\"Authorization\":\" \"}","tot":"json"},{"t":"set","p":"access_method","pt":"msg","to":"Bearer","tot":"str"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"access_method & \" \" & $flowContext('access_token')","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"{\"CaseID\":1234567890,\"DocumentName\":\"Testing .pdf POST\",\"Casepart\":{\"PartId\":12345,\"PartType\":\"Person\"},\"Documenttype\":{\"Id\":1,\"Name\":\"TestName\"},\"Beskrivelse\":\"Test\",\"file\":{\"value\":\"\",\"options\":{\"filename\":\"\"}}}","tot":"json"},{"t":"set","p":"url","pt":"msg","to":"endpointurl","tot":"env"},{"t":"set","p":"method","pt":"msg","to":"POST","tot":"str"},{"t":"set","p":"payload.file.options.filename","pt":"msg","to":"test.pdf","tot":"str"},{"t":"set","p":"payload.file.value","pt":"msg","to":"filebuffer","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":60,"wires":[["83fc6a59.f49988","9895b6e0.172548","d8424031.e4c7"]]},{"id":"d8424031.e4c7","type":"http request","z":"f08e748.bb67888","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":710,"y":60,"wires":[["c58d18bc.854a28"]]},{"id":"c58d18bc.854a28","type":"debug","z":"f08e748.bb67888","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":60,"wires":[]},{"id":"83fc6a59.f49988","type":"debug","z":"f08e748.bb67888","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"headers","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":160,"wires":[]},{"id":"9895b6e0.172548","type":"debug","z":"f08e748.bb67888","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":200,"wires":[]}]

Any inputs?

I have read the following post to try and get a bit wiser.. but to no avail (so far)

https://flows.nodered.org/flow/cbf44e064b9406a1175a7e8d589f66ac