Select to view content in your preferred language

FeatureLayer.addAttachments returns error - Unexpected token

169
2
05-09-2025 06:54 AM
MKY
by
Occasional Contributor

I have a popup trigger "Add Attachment". It invokes a function to dynamically create a form and select an attachment.

It returns an error :

MKY_0-1746798310501.png

The function addAttachment

function addAttachment(feature) { 
//create form 
const attachmentForm = document.createElement("form"); attachmentForm.setAttribute("id", "addAttachmentForm"); 
let fileSelector = document.createElement("input"); fileSelector.setAttribute("id", "fileSelector"); fileSelector.setAttribute("type", "file"); 
fileSelector.setAttribute("name", "attachment"); 
let entInput = document.createElement("input"); 
entInput.setAttribute("type", "hidden"); 
entInput.setAttribute("name", "f"); 
entInput.setAttribute("value", "json"); attachmentForm.appendChild(fileSelector); attachmentForm.appendChild(entInput); document.getElementById("resource-container").appendChild(attachmentForm); document.getElementById("fileSelector").addEventListener("change", (e) => { let selectedFiles = (e.target as any).files;
let layer = feature.layer; 
layer.addAttachment(feature, attachmentForm).then((result) => { console.log("attachment added. If successful it will return the objectID of the feature ", result);
  } }).catch((error) => { 
console.log("attachment adding failed: ", error); 
 }); 
 document.getElementById("fileSelector").click();
 }

 

Any help is appreciated

0 Kudos
2 Replies
Noah-Sager
Esri Regular Contributor

Looks like the attachment may be invalid? I would try several different attachment and/or attachment types.

0 Kudos
MKY
by
Occasional Contributor

Hi Noah,

I tried different attachments and the same error happens. The mapping is part of a bigger application.  Originally, it was .net framework MVC and the code was working fine. Recently, we upgraded to .net core 8 and the same code fails.

0 Kudos