Manually adding attachments

2965
3
08-04-2015 06:22 AM
JosephRogan
New Contributor III

Good morning,

I am attempting to add attachments to my feature layer but have encountered a problem.  I have already successfully implemented code to view and delete existing attachments, and I thought my code was correct to add them, however the error callback function says: "Error: Access is denied."  My feature layer does have editing enabled, and other tools in my app work properly.  I do have the proxy thing working so I don't believe it is that either.  Any suggestions?

// Open the file dialog
dom.byId("inputAttachmentFile").click();
console.log(dom.byId("inputAttachmentFile").value);
featureLayer1.addAttachment(editingFeature.attributes["OBJECTID"], dom.byId("formAttachment"), function()
{
 // Update the info window's html
 dom.byId("buttonEditAttachment").innerHTML = "Delete";
 dom.byId("spanAttachmentLink").innerHTML = "[link]";
 console.log("Attachement added");
}, function (err)
{
 console.log(err);
});
0 Kudos
3 Replies
BenGrod
Occasional Contributor III

Morning Joseph,

Has "Attachments" been enabled on the feature class? There are two different ways to enable attachments depending on where the feature resides. Below is a screen shot of enabling attachments for a feature which resides on ArcGIS Online. From the item details select the context menu under Layers and choose "Enable Attachments." The steps are a little different if in SDE and hosted on Portal. Hope this helps and good luck.

Attachment.jpg

JosephRogan
New Contributor III

Yes attachments are enabled.  The layer is published from my SDE.  When I test featureLayer1.hasAttachments it returns true.  Unfortunately I can't post the complete code for this site, it exists behind a firewall.  Unfortunately the AttachmentEditor widget does not meet my needs for this project either.

JosephRogan
New Contributor III

I made a stripped down version of the site to test the attachment editor widget, and it worked.  This proves to me that there isn't a problem accessing the actual feature layer or the service.

I could potentially use the AttachmentEditor if I can get it to load in my custom info window (InfoTemplate).  I'm not sure how to get this working though.  I can get it to startup in a div (and appear in my popup), but to get the line attachmentEditor.showAttachments(graphic, featureLayer1); I don't know where I'm supposed to pull the graphic objects from.  It's not wired to an event the gives that object like in the code sample.

0 Kudos