Adding attachments to feature service hosted on ArcGIS Online

2357
5
12-01-2017 12:54 PM
AneeqaAbrar1
New Contributor III

I want to add the photo taken by the user. The attachment needs to be directly sent to the feature service. 

According to an example in edit feature attachment - it's done using selectedFeature.attachments.addAttachment but in my case it's not to be uploaded using the picture chooser. Something like featureTable.attachments.addAttachment 

But that isn't working for me.

0 Kudos
5 Replies
nakulmanocha
Esri Regular Contributor

This is implemented in the AppStudio Quick Report template. You can look into the code on how to use camera component to take a  photo and attach it as an attachment. Rest of the code can be same as edit feature attachment sample.

AneeqaAbrar1
New Contributor III

Thank you for the reply Nakul but that's the whole point. Edit feature attachment sample uses 

selectedFeature.attachments.addAttachment which is not working 

0 Kudos
nakulmanocha
Esri Regular Contributor

I tested the sample and it works for me. Not sure whats the issue. Please explain and provide some screenshots.

Thanks,

Nakul

0 Kudos
AneeqaAbrar1
New Contributor III

This is my feature layer:

     FeatureLayer {
                id: featureLayer
            
                ServiceFeatureTable {
                    id: featureTable
                    url: "https://services1.arcgis.com/1tklMVd2WsYssnvp/arcgis/rest/services/%C3%9Cberwachung_Wasserv%C3%B6gel..."
                    onApplyEditsStatusChanged: {
                        if (applyEditsStatus === Enums.TaskStatusCompleted) {
                            console.log("successfully added feature");
                            featureLayer.selectFeaturesWithQuery(params, Enums.SelectionModeNew);
                        }
                    }
                    onAddFeatureStatusChanged: {
                        if (addFeatureStatus === Enums.TaskStatusCompleted) {
                            featureTable.applyEdits();
                        }
                    }
                }
                onSelectFeaturesStatusChanged: {
                    if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
                      selectedFeature = selectFeaturesResult.iterator.next();
                      selectedFeature.attachments.addAttachment(attachment, "application/octet-stream");
                    }
                }
            }

This is my mouseclick event

        onMouseClicked: {
                    clicking++
                    console.log("This is an attachment",attachment)                     
                            var featureAttributesOnline = {"Datum": new Date(),"Spezie" : spezie, "SeasonalBirds" : seasonalbird, "Distanz" : distanz, "Anzahl" : anzahl,
                                                      "Beschaeftigung" : beschaeftigung, "Ueberflutungs" : ueberflutungssituation, "Wetter" : wetter, "AppNum": "1", "Benutzer":uid};
                            var featureOnline = featureTable.createFeatureWithAttributes(featureAttributesOnline, mouse.mapPoint);
                            featureTable.addFeature(featureOnline);
                            selectedFeature.attachments.addAttachment(attachment)           
        }

Now theoretically, along with my feature creation my photo should also be uploaded - but that's not the case.
0 Kudos
nakulmanocha
Esri Regular Contributor

I am able to attach an image using the Edit Feature Attachments sample for the existing feature of your feature layer. The attachment can be seen here

https://services1.arcgis.com/1tklMVd2WsYssnvp/ArcGIS/rest/services/%C3%9Cberwachung_Wasserv%C3%B6gel... 

Also, you cannot have addfeature and addattachment code lines next to each other. They are asynchronous process and needs to handled separately.

You psuedo code should be

1) Mouse click 

2) Add feature

3) Apply edits

4) Once feature successfully created and added. 

5) Then you can call for addattachments code directly within the applyeditsstatuschanged to completed.

In that case you have to look for that feature if created then call add attachment code.

6)If you wanna use a FileDialog to select a file. You need to wait for the feature to be created. Then you need to click on that feature and select that feature and provide a dialog to upload attachment as done in our sample.

See Add or Delete Sample & Edit Feature Attachments samples. Basically you need to put these two samples together.

Please create a support ticket and they should be able to guide you through this process if you having difficulty.

Thanks,

Nakul

0 Kudos