I have a popup trigger "Add Attachment". It invokes a function to dynamically create a form and select an attachment.
It returns an error :
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
Looks like the attachment may be invalid? I would try several different attachment and/or attachment types.
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.