Deploying DMN Decision Table by REST API (POST) fails with jQuery

When I try to deploy my DMN (xml) to the Camunda REST-API it works perfect with the Camunda Modeler Tool.
Next I try to post it by Postman with adding the key - value by form-data and with the xml file - WORKS.
Now I want to post it by jQuery with my own code - FAILS.
I’m still able to post values to the Decision Table to get the output back… this works.
Currently I get back a 415 error - but I don’t know what I’m doing wrong.

var Url = 'http://my.camunda.server:8081/engine-rest/deployment/create';

var form = new FormData();
form.append("deployment-name", "test");
form.append("enable-duplicate-filtering", "true");
form.append("data", "dmn/mydmnfile.dmn");

var Param = {
    "async": true,
    "crossDomain": true,
    "url": Url,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "processData": false,
    "contentType": false,
    "mimeType": "multipart/form-data",
    "data": form
}

fetch(Url,Param)
.then(function(response)
{
    if (response.ok)
    {
        return response.json();
    }
    else
    {
        console.log(response);
        $("#return_box").html('FEHLER!<BR>' + response.statusText);
    }
})
.then(function(data)
{
    console.log("OK");
})
.catch(function(error)
{
    console.log(error.message);
});

Yeah! Got it!! :slight_smile: Here is the working solution for everyone who has the same problem:

<?php /* erster AJAX-Request liest die XML-Datei mit dem DMN als Plaintext aus und schreibt diese bei Erfolg in die Variable data */ ?>
$.ajax({
    <?php /* Datei die ausgelesen werden soll (inkl. Pfad) */ ?>
    url : "dmn/file.dmn",
    dataType: "text",
    success: function(data) {
        <?php /* Zunächst wird aus dem XML-String im Plaintext ein Blob-Objekt erzeugt, damit später FormData damit arbeiten kann */ ?>
        var fileStringArray = [data];
        var fileName = "file.dmn";
        var blobAttrs = {type: "xml"};
        var file = new File(fileStringArray, fileName, blobAttrs);

        <?php /* Neue Data-Form starten, der dann alle Parameter angehängt werden */ ?>
        var data = new FormData();
        data.append("deployment-name", "test");
        data.append("enable-duplicate-filtering", "true");
        data.append("deployment-source", "process application");
        data.append("data", file, file.name);

        <?php /* zweiter AJAX-Request macht die API-Anfrage per POST und deployt die DMN-Definition */ ?>
        $.ajax({
            url: "http://my.camunda.server:8081/engine-rest/deployment/create",
            type: "POST",
            data: data,
            enctype: 'multipart/form-data',
            async: true,
            crossDomain: true,
            processData: false,
            contentType: false,
            cache: false,
            timeout: 0,
            success: function(data) {
                console.log("Deployment erfolgreich: ", data);
            },
            error: function(e) {
                console.log("FEHLER : ", e);
            }
        });
    },
    error: function(data) {
        console.log("FEHLER! Die Datei konnte nicht ausgelesen werden.");
    }
});