<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Add attachments from HTML File Input JS 4.20 in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091158#M74366</link>
    <description>&lt;P&gt;I have a custom html form for users to supply information and a map for them to capture a site boundary. The form includes the option to upload file attachments. The feature layer i'm writing to has attachments enabled and is published from our enterprise geodatabase. On submitting the form I can create the new feature with attributes, but I'm struggling with how to then add the file attachments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function submitSite(){
  const attributes = {};
  attributes["Info"] = dom.byId("Info").value;
  attributes["Info2"] = dom.byId("Info2").value;
  attributes["Info3"] = dom.byId("Info3").value;
  graphicsLayer.graphics.items[0].attributes = attributes;
  // sites = featureLayer
  sites.applyEdits({
    addFeatures:[graphicsLayer.graphics.items[0]]
  }).then((submittedResponse) =&amp;gt; {				
    if(submittedResponse.addFeatureResults[0].error == null){
      const globId = submittedResponse.addFeatureResults[0].globalId;
      sites.definitionExpression = "GlobalID = '" + globId + "'";
      // How do i now add the attchments to this feature
    }
  });
}&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form class="attachForm" id="attachment-1" &amp;gt;	
  &amp;lt;label for="myFile" class="form-label"&amp;gt;Attach file&amp;lt;/label&amp;gt;
  &amp;lt;input class="form-control" type="file" name="attachment" accept=".pdf" id="myFile"&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;I'm not sure on how to get the file from the input form and how to add it to the new feature as the feature has not been clicked in the map. I've tried using the example provided here&amp;nbsp;&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#addAttachment" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#addAttachment&lt;/A&gt;&amp;nbsp;but I keep getting various errors.&lt;/P&gt;&lt;P&gt;Any help on how the achieve this would be much appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Aug 2021 09:02:51 GMT</pubDate>
    <dc:creator>JoCondliffe</dc:creator>
    <dc:date>2021-08-23T09:02:51Z</dc:date>
    <item>
      <title>Add attachments from HTML File Input JS 4.20</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091158#M74366</link>
      <description>&lt;P&gt;I have a custom html form for users to supply information and a map for them to capture a site boundary. The form includes the option to upload file attachments. The feature layer i'm writing to has attachments enabled and is published from our enterprise geodatabase. On submitting the form I can create the new feature with attributes, but I'm struggling with how to then add the file attachments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function submitSite(){
  const attributes = {};
  attributes["Info"] = dom.byId("Info").value;
  attributes["Info2"] = dom.byId("Info2").value;
  attributes["Info3"] = dom.byId("Info3").value;
  graphicsLayer.graphics.items[0].attributes = attributes;
  // sites = featureLayer
  sites.applyEdits({
    addFeatures:[graphicsLayer.graphics.items[0]]
  }).then((submittedResponse) =&amp;gt; {				
    if(submittedResponse.addFeatureResults[0].error == null){
      const globId = submittedResponse.addFeatureResults[0].globalId;
      sites.definitionExpression = "GlobalID = '" + globId + "'";
      // How do i now add the attchments to this feature
    }
  });
}&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form class="attachForm" id="attachment-1" &amp;gt;	
  &amp;lt;label for="myFile" class="form-label"&amp;gt;Attach file&amp;lt;/label&amp;gt;
  &amp;lt;input class="form-control" type="file" name="attachment" accept=".pdf" id="myFile"&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;I'm not sure on how to get the file from the input form and how to add it to the new feature as the feature has not been clicked in the map. I've tried using the example provided here&amp;nbsp;&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#addAttachment" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#addAttachment&lt;/A&gt;&amp;nbsp;but I keep getting various errors.&lt;/P&gt;&lt;P&gt;Any help on how the achieve this would be much appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 09:02:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091158#M74366</guid>
      <dc:creator>JoCondliffe</dc:creator>
      <dc:date>2021-08-23T09:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Add attachments from HTML File Input JS 4.20</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091243#M74373</link>
      <description>&lt;P&gt;That documentation has a snippet on how to convert an HTML form to FormData and use the addAttchment method. What errors do you see and do you have a sample showing the errors?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 14:40:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091243#M74373</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-08-23T14:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Add attachments from HTML File Input JS 4.20</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091285#M74379</link>
      <description>&lt;P&gt;Hi, I dont find the documentation snippet very help full as it defines the variable 'form' twice (throwing an error) and doesn't explain where the parameter 'file' comes from in the line&amp;nbsp;&lt;SPAN&gt;form.set(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"attachment"&lt;/SPAN&gt;&lt;SPAN&gt;, file); which gives me an error - Uncaught (in promise) ReferenceError: file is not defined. I've never used file input forms before so it might be my naivety but it would be helpful if this could be explained. Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 16:22:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091285#M74379</guid>
      <dc:creator>JoCondliffe</dc:creator>
      <dc:date>2021-08-23T16:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Add attachments from HTML File Input JS 4.20</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091296#M74382</link>
      <description>&lt;P&gt;Weird, ok. The API is even simpler as you can just pass the DOM Element for the form, and the JSAPI will take care of the rest.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/Pojobpe?editors=0010" target="_blank"&gt;https://codepen.io/odoe/pen/Pojobpe?editors=0010&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.when(function () {
  view.on("click", function (event) {
    view.hitTest(event).then((response) =&amp;gt; {
      const feature = response.results[0].graphic;
      const attachmentForm = document.getElementById("uploadForm");
      layer.addAttachment(feature, attachmentForm).then((result) =&amp;gt; {
        console.log("attachment added: ", result);
      })
      .catch(function (err) {
        console.log("attachment adding failed: ", err);
      });
    });
  });
});&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 23 Aug 2021 16:53:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091296#M74382</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-08-23T16:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Add attachments from HTML File Input JS 4.20</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091633#M74389</link>
      <description>&lt;P&gt;That makes so much more sense! Works perfectly. Thanks very much for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 09:47:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-attachments-from-html-file-input-js-4-20/m-p/1091633#M74389</guid>
      <dc:creator>JoCondliffe</dc:creator>
      <dc:date>2021-08-24T09:47:04Z</dc:date>
    </item>
  </channel>
</rss>

