getMultipartItem returns object, but getMultipartStream returns undefined

Enonic version: 7.1.1
OS: Windows 10


I’m creating a contact form where the user has the option to upload attachments.


<form method="post" id="conntactForm" data-th-action="${serviceUrl}" action="#" role="contactUs"  target="hiddenFrame" enctype="multipart/form-data" class="form mr-auto">
<input type="file" class="btn btn-primary" name="image">Legg til bilder<input>

I’m using this code in the service:

var image = portalLib.getMultipartItem('image');; 

var imageStream = portalLib.getMultipartStream('image');

“name”: “image”,
“fileName”: “Org-kart-2020.png”,
“contentType”: “image/png”,
“size”: 931330

but imageStream returns undefined.

I’m I missing something?

  1. Your html is broken. <input> is not a container element, it should be properly closed. In your case there’s second unnamed input in the form.

  2. getMultipartStream() returns a binary stream, not JSON. You cannot JSON.stringify it.