getMultipartItem returns object, but getMultipartStream returns undefined


#1

Enonic version: 7.1.1
OS: Windows 10

Hi,

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

Form:

<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>
</form>

I’m using this code in the service:

var image = portalLib.getMultipartItem('image');
log.info(JSON.stringify(image)); 

var imageStream = portalLib.getMultipartStream('image')
log.info(JSON.stringify(imageStream));

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

but imageStream returns undefined.

I’m I missing something?


#2
  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.