<?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 Re: https://www.arcgis.com/sharing/rest/content/features/generate Error in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080849#M73952</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have added the code through insertCode option. Thanks for letting me know.&lt;/P&gt;&lt;P&gt;Can someone help me why&amp;nbsp;&amp;nbsp;&lt;A href="https://www.arcgis.com/sharing/rest/content/features/generate" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.arcgis.com/sharing/rest/content/features/generate&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; is returning a html instead of json response in the attached code.&lt;/P&gt;&lt;P&gt;getting error -&amp;nbsp; Unexpected token '&amp;lt;'&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const fileName='';

document
    .getElementById("uploadForm")
    .addEventListener("change", (event) =&amp;gt; {
               fileName = event.target.value.toLowerCase();
});			   

//filepath is from local drive: D:\GIS\tl_2020_39_tabblock20.zip
	
const portalUrl = "https://www.arcgis.com";
let name = fileName.split(".");
name = name[0].replace("c:\\fakepath\\", "");

            var params = {
                'name': name,
                'targetSR': this.map.spatialReference,
                'maxRecordCount': 1000,
                'enforceInputFileSizeLimit': true,
                'enforceOutputJsonSizeLimit': true
            };

            var extent = scaleUtils.getExtentForScale(this.map, 40000);
            var resolution = extent.getWidth() / this.map.width;
            params.generalize = true;
            params.maxAllowableOffset = resolution;
            params.reducePrecision = true;
            params.numberOfDigitsAfterDecimal = 0;


            var myContent = {
                'filetype': 'shapefile',
                'publishParameters': JSON.stringify(params),
                'f': 'json'                
            };

            console.log(document.getElementById("uploadForm"));

            esriRequest({
                url: portalUrl + "/sharing/rest/content/features/generate",
                query: myContent,
                form: document.getElementById("uploadForm"),
                handleAs: "json",
                load: lang.hitch(this, function (response) {
                    if (response.error) {
                        errorHandler(response.error);
                        return;
                    }

var layerName = response.featureCollection.layers[0].layerDefinition.name;                   
addShapefileToMap(response.featureCollection);
                }),
                error: lang.hitch(this, errorHandler)
            });


            function errorHandler(error) {
                console.log('error!!');
            }



            function addShapefileToMap(featureCollection) {
                let sourceGraphics = [];
                const layers = featureCollection.layers.map((layer) =&amp;gt; {
         const graphics = layer.featureSet.features.map((feature) =&amp;gt; {
                        return Graphic.fromJSON(feature);
                    });

                    sourceGraphics = sourceGraphics.concat(graphics);
                    const featureLayer = new FeatureLayer({
                        objectIdField: "FID",
                       source: graphics,
                    fields: layer.layerDefinition.fields.map((field) =&amp;gt; {
                            return Field.fromJSON(field);
                        })
                    });
                    return featureLayer;
                });

                this.map.addMany(layers);
            };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Chitra&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jul 2021 14:42:57 GMT</pubDate>
    <dc:creator>ChitraKrishnan</dc:creator>
    <dc:date>2021-07-20T14:42:57Z</dc:date>
    <item>
      <title>https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080507#M73938</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Can somebody help me why&amp;nbsp;&amp;nbsp;&lt;A href="https://www.arcgis.com/sharing/rest/content/features/generate" target="_blank"&gt;https://www.arcgis.com/sharing/rest/content/features/generate&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; is returning a html instead of json response in the attached code.&lt;/P&gt;&lt;P&gt;getting error -&amp;nbsp; Unexpected token '&amp;lt;'&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Chitra&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 20:48:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080507#M73938</guid>
      <dc:creator>ChitraKrishnan</dc:creator>
      <dc:date>2021-07-19T20:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080539#M73941</link>
      <description>&lt;P&gt;Instead of providing code as an attachment, please add it using "Insert code sample".&amp;nbsp; It makes it much easier to read your code and help you.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_blank"&gt;https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 21:09:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080539#M73941</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2021-07-19T21:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080849#M73952</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have added the code through insertCode option. Thanks for letting me know.&lt;/P&gt;&lt;P&gt;Can someone help me why&amp;nbsp;&amp;nbsp;&lt;A href="https://www.arcgis.com/sharing/rest/content/features/generate" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.arcgis.com/sharing/rest/content/features/generate&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; is returning a html instead of json response in the attached code.&lt;/P&gt;&lt;P&gt;getting error -&amp;nbsp; Unexpected token '&amp;lt;'&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const fileName='';

document
    .getElementById("uploadForm")
    .addEventListener("change", (event) =&amp;gt; {
               fileName = event.target.value.toLowerCase();
});			   

//filepath is from local drive: D:\GIS\tl_2020_39_tabblock20.zip
	
const portalUrl = "https://www.arcgis.com";
let name = fileName.split(".");
name = name[0].replace("c:\\fakepath\\", "");

            var params = {
                'name': name,
                'targetSR': this.map.spatialReference,
                'maxRecordCount': 1000,
                'enforceInputFileSizeLimit': true,
                'enforceOutputJsonSizeLimit': true
            };

            var extent = scaleUtils.getExtentForScale(this.map, 40000);
            var resolution = extent.getWidth() / this.map.width;
            params.generalize = true;
            params.maxAllowableOffset = resolution;
            params.reducePrecision = true;
            params.numberOfDigitsAfterDecimal = 0;


            var myContent = {
                'filetype': 'shapefile',
                'publishParameters': JSON.stringify(params),
                'f': 'json'                
            };

            console.log(document.getElementById("uploadForm"));

            esriRequest({
                url: portalUrl + "/sharing/rest/content/features/generate",
                query: myContent,
                form: document.getElementById("uploadForm"),
                handleAs: "json",
                load: lang.hitch(this, function (response) {
                    if (response.error) {
                        errorHandler(response.error);
                        return;
                    }

var layerName = response.featureCollection.layers[0].layerDefinition.name;                   
addShapefileToMap(response.featureCollection);
                }),
                error: lang.hitch(this, errorHandler)
            });


            function errorHandler(error) {
                console.log('error!!');
            }



            function addShapefileToMap(featureCollection) {
                let sourceGraphics = [];
                const layers = featureCollection.layers.map((layer) =&amp;gt; {
         const graphics = layer.featureSet.features.map((feature) =&amp;gt; {
                        return Graphic.fromJSON(feature);
                    });

                    sourceGraphics = sourceGraphics.concat(graphics);
                    const featureLayer = new FeatureLayer({
                        objectIdField: "FID",
                       source: graphics,
                    fields: layer.layerDefinition.fields.map((field) =&amp;gt; {
                            return Field.fromJSON(field);
                        })
                    });
                    return featureLayer;
                });

                this.map.addMany(layers);
            };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Chitra&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 14:42:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080849#M73952</guid>
      <dc:creator>ChitraKrishnan</dc:creator>
      <dc:date>2021-07-20T14:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080935#M73957</link>
      <description>&lt;P&gt;is this in 3x or 4x?&lt;/P&gt;&lt;P&gt;I thought it was 3x because you are using handleAs, but passing a query. In 3x, &lt;A href="https://developers.arcgis.com/javascript/3/jsapi/esri.request-amd.html#esrirequest" target="_self"&gt;it's content, not query&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;But if you are using 4x, it's query, but you should use &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html#RequestOptions" target="_self"&gt;responseType&lt;/A&gt;, not handleAs.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 17:00:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1080935#M73957</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-07-20T17:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081028#M73958</link>
      <description>&lt;P&gt;we are using 3x.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified the code as below and getting a different error. Is my code correct?&lt;/P&gt;&lt;P&gt;{"error":{"code":405,"messageCode":"GWM_0005","message":"Method not supported.","details":[]}}&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;            var layersRequest = esriRequest({
                url: portalUrl + "/sharing/rest/content/features/generate",
                content: { 'f': "json", 'filetype': 'shapefile', 'publishParameters': JSON.stringify(params) },
                handleAs: "json"
            });

            layersRequest.then(
                function (response) {
                    console.log("Success: ", response.layers);
                }, function (error) {
                    console.log("Error: ", error.message);
                });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 19:37:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081028#M73958</guid>
      <dc:creator>ChitraKrishnan</dc:creator>
      <dc:date>2021-07-20T19:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081057#M73959</link>
      <description>&lt;P&gt;The only difference I can see at a glance from your code and the sample is the sample adds a callback.html parameter.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/3/jssamples/portal_addshapefile.html" target="_blank"&gt;https://developers.arcgis.com/javascript/3/jssamples/portal_addshapefile.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;When you add the form, I think it should automatically make a POST request. Maybe verify that as well.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 20:35:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081057#M73959</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-07-20T20:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081063#M73960</link>
      <description>&lt;P&gt;I got the error code 405 resolved. I was referencing&amp;nbsp;portalUrl as this.portalUrl.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But again I am back to the same error, the generate returning&amp;nbsp;a html instead of json response&amp;nbsp;&lt;/P&gt;&lt;P&gt;error -&amp;nbsp; Unexpected token '&amp;lt;'&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;div&amp;gt;
    &amp;lt;div data-dojo-attach-point="mapNode"&amp;gt;&amp;lt;/div&amp;gt;

    &amp;lt;div&amp;gt;
        &amp;lt;form enctype="multipart/form-data" method="post" id="uploadForm"&amp;gt;
            &amp;lt;div class="field"&amp;gt;
                &amp;lt;label class="file-upload"&amp;gt;
                    &amp;lt;span&amp;gt;&amp;lt;strong&amp;gt;Add File&amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;
                    &amp;lt;input type="file" name="file" id="inFile" /&amp;gt;
                &amp;lt;/label&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;


&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const fileName='';

document
    .getElementById("uploadForm")
    .addEventListener("change", (event) =&amp;gt; {
               fileName = event.target.value.toLowerCase();
});			   

//filepath is from local drive: D:\GIS\tl_2020_39_tabblock20.zip
	
const portalUrl = "https://www.arcgis.com";
let name = fileName.split(".");
name = name[0].replace("c:\\fakepath\\", "");

 var params = {
                'name': name,
                'targetSR': this.map.spatialReference,
                'maxRecordCount': 1000,
                'enforceInputFileSizeLimit': true,
                'enforceOutputJsonSizeLimit': true
            };

            var extent = scaleUtils.getExtentForScale(this.map, 40000);
            var resolution = extent.getWidth() / this.map.width;
            params.generalize = true;
            params.maxAllowableOffset = resolution;
            params.reducePrecision = true;
            params.numberOfDigitsAfterDecimal = 0;

            var myContent = {
                'filetype': 'shapefile',
                'publishParameters': JSON.stringify(params),
                'f': 'json'                
            };


            console.log(document.getElementById("uploadForm"));
            console.log(dom.byId("uploadForm"));


            var layersRequest = esriRequest({
                url: portalUrl + "/sharing/rest/content/features/generate",                
                content: myContent,
                handleAs: "json",              
                form: document.getElementById("uploadForm")
            }, { usePost: 'true', });

            layersRequest.then(
                function (response) {
                    console.log("Success: ", response.layers);
                }, function (error) {
                    console.log("Error: ", error.message);
                });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 20:52:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081063#M73960</guid>
      <dc:creator>ChitraKrishnan</dc:creator>
      <dc:date>2021-07-20T20:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: https://www.arcgis.com/sharing/rest/content/features/generate Error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081518#M73973</link>
      <description>&lt;P&gt;I copied the sample code from&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-shapefile" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-shapefile&lt;/A&gt; to my local and it works for&amp;nbsp;drp_county_boundary.zip. But when I try to load&amp;nbsp;tl_2020_39_tabblock20.zip it throws below error&lt;/P&gt;&lt;P&gt;Index:1 Access to fetch at '&lt;A href="https://www.arcgis.com/sharing/rest/content/features/generate?filetype=shapefile&amp;amp;publishParameters=%7B%22name%22%3A%22tl_2020_39_tabblock20%22%2C%22targetSR%22%3A%7B%22latestWkid%22%3A3857%2C%22wkid%22%3A102100%7D%2C%22maxRecordCount%22%3A1000%2C%22enforceInputFileSizeLimit%22%3Atrue%2C%22enforceOutputJsonSizeLimit%22%3Atrue%2C%22generalize%22%3Atrue%2C%22maxAllowableOffset%22%3A10%2C%22reducePrecision%22%3Atrue%2C%22numberOfDigitsAfterDecimal%22%3A0%7D&amp;amp;f=json" target="_blank"&gt;https://www.arcgis.com/sharing/rest/content/features/generate?filetype=shapefile&amp;amp;publishParameters=%7B%22name%22%3A%22tl_2020_39_tabblock20%22%2C%22targetSR%22%3A%7B%22latestWkid%22%3A3857%2C%22wkid%22%3A102100%7D%2C%22maxRecordCount%22%3A1000%2C%22enforceInputFileSizeLimit%22%3Atrue%2C%22enforceOutputJsonSizeLimit%22%3Atrue%2C%22generalize%22%3Atrue%2C%22maxAllowableOffset%22%3A10%2C%22reducePrecision%22%3Atrue%2C%22numberOfDigitsAfterDecimal%22%3A0%7D&amp;amp;f=json&lt;/A&gt;' from origin '&lt;A href="http://localhost" target="_blank"&gt;http://localhost&lt;/A&gt;' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Chitra&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 20:14:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/https-www-arcgis-com-sharing-rest-content-features/m-p/1081518#M73973</guid>
      <dc:creator>ChitraKrishnan</dc:creator>
      <dc:date>2021-07-21T20:14:51Z</dc:date>
    </item>
  </channel>
</rss>

