Home > Forum > Rules, JS, SQL > Q: Is it possible to ADD ATTACHMENTS directly from JavaScript (blob)?

Q: Is it possible to ADD ATTACHMENTS directly from JavaScript (blob)?
0

MVP

Hello everyone,

I’m still learning how to use JavaScript effectively with WEBCON BPS.
Currently, I’m working on a project that involves an HTML button/JavaScript triggering a file download at the end:

JAVASCRIPT:
// Save the PDF and offer it for download
const pollerPdfBytes = await pollerPdf.save();
const blob = new Blob([pollerPdfBytes], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'poller.pdf';
link.click();
URL.revokeObjectURL(url);
});
</script>

This works perfectly.
However, instead of downloading the file, I would prefer to attach the file (poller.pdf) directly to the current instance as an attachment.

Is this even possible with JavaScript?
If not, what other options could I use?

I’d be grateful for any tips that could help me move forward.

Best regards,
Bjoern

MVP
In reply to: Bartosz Kusiak

Do you wamt tp add the functionality to existing element or for an element without WFD_ID (new element)

Subject: Adding a Merged PDF to an Existing Instance via JavaScript

Good Morning Bartosz,

I have an existing instance and would like to add a merged PDF file (poller.pdf) directly via JavaScript, rather than downloading it. If we can make this approach work, I’d be happy to publish the code and, of course, give credit where it’s due.

Do you have any suggestions or ideas on how to implement this?


Best regards,
Björn

In reply to: Bjoern Poller

Subject: Adding a Merged PDF to an Existing Instance via JavaScript

Good Morning Bartosz,

I have an existing instance and would like to add a merged PDF file (poller.pdf) directly via JavaScript, rather than downloading it. If we can make this approach work, I’d be happy to publish the code and, of course, give credit where it’s due.

Do you have any suggestions or ideas on how to implement this?


Best regards,
Björn

1. Create a tech field multiline
2. Save blob data to the field - for example as base64
3. Create new menu action and there use add attachment and instead id add the attachment depends on sql
SELECT CAST('' AS XML).value('xs:base64Binary("{techField}")', 'VARBINARY(MAX)') AS Content, 'file1.txt' AS FileName
4. Clear Tech field
5. Create html button or what you want and invoke the action from menu