Attach file to jira issue using AP.request in Jira Cloud

Hello ,
I would like to add attachment to Jira(cloud) issue using AP.request but i got the error 415 , here is my code snippet

function uploadAttachment(issueIdOrKey, fileToUpload) {
    var theRequestURL = `/rest/api/3/issue/${issueIdOrKey}/attachments`;
    AP.request({
        url: theRequestURL,
        type: 'POST',
        data: {file: fileToUpload},
        async: true,
        processData: false,
        contentType: false,
       headers: {
         'X-Atlassian-Token': 'no-check',
         'Accept': 'application/json'
     },
        success: function(responseText) {
            console.log('Upload success:', responseText);
            alert('Attachment uploaded successfully.');
        },
        error: function(xhr, textStatus, errorThrown) {
            console.error('Error uploading attachment:', errorThrown);
            alert("Failed to upload attachment. Please try again.");
        }
    });
}

someone could help please ?

Is the attachment posted as multipart/form-data? it is mentioned as requirement in the docs. This is the example shown in the doc as well:

// This code sample uses the 'node-fetch' and 'form-data' libraries:
 // https://www.npmjs.com/package/node-fetch
 // https://www.npmjs.com/package/form-data
 const fetch = require('node-fetch');
 const FormData = require('form-data');
 const fs = require('fs');

 const filePath = 'myfile.txt';
 const form = new FormData();
 const stats = fs.statSync(filePath);
 const fileSizeInBytes = stats.size;
 const fileStream = fs.createReadStream(filePath);

 form.append('file', fileStream, {knownLength: fileSizeInBytes});

 fetch('https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments', {
     method: 'POST',
     body: form,
     headers: {
         'Authorization': `Basic ${Buffer.from(
             'email@example.com:'
         ).toString('base64')}`,
         'Accept': 'application/json',
         'X-Atlassian-Token': 'no-check'
     }
 })
     .then(response => {
         console.log(
             `Response: ${response.status} ${response.statusText}`
         );
         return response.text();
     })
     .then(text => console.log(text))
     .catch(err => console.error(err));