Adds an attachment to a feature.
Adds an attachment to a feature. This operation is available only if the layer's
capabilities.data.supportsAttachment is set to true.
Feature to which the attachment is to be added.
HTML form that contains a file upload field pointing to the file to be added as an attachment.
When resolved, a FeatureEditResult
object is returned. FeatureEditResult indicates whether or not the edit was successful. If successful, the objectId of the result is the Id of
the new attachment. If unsuccessful, it also includes an error name and error message.
view.when(function () {
view.on("click", function (event) {
view.hitTest(event).then(function (response) {
const feature = response.results[0].graphic;
// The form is defined as below in the html.
// For enterprise services:
// 1. File input name must be "attachment"
// <form id="attachmentForm">
// Select a file: <input type="file" name="attachment">
// </form>
const attachmentForm = document.getElementById("attachmentForm");
const formData = new FormData(attachmentForm);
// For enterprise services - add input with name:f and value:json
formData.append("f","json");
const form = new FormData();
form.set("attachment", file);
form.append("f","json")
let form = document.getElementById("myForm");
// Add an attachment to the clicked feature.
// The attachment is taken from the form.
layer.addAttachment(feature, form).then(function (result) {
console.log("attachment added: ", result);
})
.catch(function (err) {
console.log("attachment adding failed: ", err);
});
});
});
});
Deletes attachments from a feature.
Deletes attachments from a feature. This operation is available only if the layer's
capabilities.data.supportsAttachment is set to true.
Feature containing attachments to be deleted.
Ids of the attachments to be deleted.
When resolved, an array of FeatureEditResults
is returned. FeatureEditResult indicates whether or not the edit was successful. If successful, the objectId of the result is the Id of
the new attachment. If unsuccessful, it also includes an error name and error message.
A feature source that support attachments.