# Interface AttachmentEnabledLayer

A feature source that support attachments.

interface AttachmentEnabledLayer {
addAttachment: ((feature: Graphic, attachment: FormData | HTMLFormElement) => Promise<FeatureEditResult>);
deleteAttachments: ((feature: Graphic, attachmentIds: number[]) => Promise<FeatureEditResult[]>);
}

#####
Index

### Properties

addAttachment
deleteAttachments

##
Properties

### addAttachment

addAttachment: ((feature: Graphic, attachment: FormData | HTMLFormElement) => Promise<FeatureEditResult>)

Adds an attachment to a feature.

#### Type declaration

- - (feature, attachment): Promise<FeatureEditResult>

  - Adds an attachment to a feature. This operation is available only if the layer's capabilities.data.supportsAttachment is set to `true`.

    #### Parameters

    - feature: Graphic

      Feature to which the attachment is to be added.

    - attachment: FormData | HTMLFormElement

      HTML form that contains a file upload field pointing to the file to be added as an attachment.

    #### Returns Promise<FeatureEditResult>

    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`.

    #### Since

    4.9

    #### See

    capabilities.data.supportsAttachment

    #### Example

        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);
              });
            });
          });
        });

### deleteAttachments

deleteAttachments: ((feature: Graphic, attachmentIds: number[]) => Promise<FeatureEditResult[]>)

Deletes attachments from a feature.

#### Type declaration

- - (feature, attachmentIds): Promise<FeatureEditResult[]>

  - Deletes attachments from a feature. This operation is available only if the layer's capabilities.data.supportsAttachment is set to `true`.

    #### Parameters

    - feature: Graphic

      Feature containing attachments to be deleted.

    - attachmentIds: number[]

      Ids of the attachments to be deleted.

    #### Returns Promise<FeatureEditResult[]>

    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`.

    #### Since

    4.9

    #### See

    capabilities.data.supportsAttachment