View on GitHub Sample viewer app

Add, delete, and download attachments for features from a service.

Image of edit feature attachments

Use case

Attachments provide a flexible way to manage additional information that is related to your features. Attachments allow you to add files to individual features, including: PDFs, text documents, or any other type of file. For example, if you have a feature representing a building, you could use attachments to add multiple photographs of the building taken from several angles, along with PDF files containing the building’s deed and tax information.

How to use the sample

Click a feature on the map to select it. Click ‘Add Attachment’ to add an attachment to the selected feature. The list view will update to show the attachments of the selected feature (if any). To delete an attachment, first select the feature, and then select an attachment from the list view. Then click ‘Delete Attachment’ to delete the selected attachment.

How it works

  1. Create a ServiceFeatureTable from a URL.
  2. Create a FeatureLayer object from the service feature table.
  3. Select features from the feature layer with selectFeatures.
  4. To fetch the feature’s attachments, cast to an ArcGISFeature and useArcGISFeature.fetchAttachmentsAsync().
  5. To add an attachment to the selected ArcGISFeature, create an attachment and use ArcGISFeature.addAttachmentAsync().
  6. To delete an attachment from the selected ArcGISFeature, use the ArcGISFeature.deleteAttachmentAsync().
  7. After a change, apply the changes to the server using ServiceFeatureTable.applyEditsAsync().

Additional information

Attachments can only be added to and accessed on service feature tables when their hasAttachments property is true.

Relevant API

  • ArcGISFeature
  • FeatureLayer
  • ServiceFeatureTable

Tags

Edit and Manage Data, image, picture, JPEG, PNG, PDF, TXT

Sample Code

module-info.java module-info.java EditFeatureAttachmentsSample.java
/*
* Copyright 2022 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module com.esri.samples.edit_feature_attachments {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
// require other modules that the application uses
requires org.apache.commons.io;
exports com.esri.samples.edit_feature_attachments;
}