I have a custom html form for users to supply information and a map for them to capture a site boundary. The form includes the option to upload file attachments. The feature layer i'm writing to has attachments enabled and is published from our enterprise geodatabase. On submitting the form I can create the new feature with attributes, but I'm struggling with how to then add the file attachments.
function submitSite(){
const attributes = {};
attributes["Info"] = dom.byId("Info").value;
attributes["Info2"] = dom.byId("Info2").value;
attributes["Info3"] = dom.byId("Info3").value;
graphicsLayer.graphics.items[0].attributes = attributes;
// sites = featureLayer
sites.applyEdits({
addFeatures:[graphicsLayer.graphics.items[0]]
}).then((submittedResponse) => {
if(submittedResponse.addFeatureResults[0].error == null){
const globId = submittedResponse.addFeatureResults[0].globalId;
sites.definitionExpression = "GlobalID = '" + globId + "'";
// How do i now add the attchments to this feature
}
});
}
<form class="attachForm" id="attachment-1" >
<label for="myFile" class="form-label">Attach file</label>
<input class="form-control" type="file" name="attachment" accept=".pdf" id="myFile">
</form>
I'm not sure on how to get the file from the input form and how to add it to the new feature as the feature has not been clicked in the map. I've tried using the example provided here https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#addAttac... but I keep getting various errors.
Any help on how the achieve this would be much appreciated.