Adding a shapefile to a feature layer using arcgis js api

05-03-2017 05:28 AM
New Contributor

I have the following code and up until a couple of weeks ago (or possibly one or two months because I hadn't used it in some time) everything seemed to be working fine:

function generateFeatureCollection(fileName) {    require(["esri/geometry/scaleUtils", "esri/request", "dojo/dom", "dojo/on", "dojo/_base/lang"], function (scaleUtils, request, dom, on, lang) {        var portalUrl = "";"progress"); = 'progress';        //resolving the fakepath issue in the file location url        var name = fileName.split(".");        name = name[0].replace("c:\\fakepath\\", "");         var params = {            'name': name,            'targetSR':,            'maxRecordCount': 12500,            'enforceInputFileSizeLimit': true,            'enforceOutputJsonSizeLimit': true        };         var extent = scaleUtils.getExtentForScale(, 40000);        var resolution = extent.getWidth() /;        params.generalize = true;        params.maxAllowableOffset = resolution;        params.reducePrecision = true;        params.numberOfDigitsAfterDecimal = 0;         var myContent = {            'filetype': 'shapefile',            'publishParameters': JSON.stringify(params),            'f': 'json',            'callback.html': 'textarea'        };         var genRequest = request({            url: portalUrl + '/sharing/rest/content/features/generate',            content: myContent,            form: dom.byId('uploadForm'),            handleAs: 'json',            load: lang.hitch(this, function (response) {                if (response.error) {                    return;                }                addShapefileToMap(response.featureCollection);            }),        });        genRequest.then(            function (response) {                //console.log("Success: ", response.layers);            }, function (error) {                app.notifyError("Error on upload.");                $('#IEFill').append("<b>Upload Error: "+error+"</b>");            });    });}

However recently an error is being thrown in the last part of the code where the line is:

app.notifyError("Error on upload.");

The following error is being thrown and I have been through all my code and have no idea what I may be doing wrong especially since this process was working and no changes were made to the best of my knowledge.

SyntaxError: Unexpected token <at Object.b.fromJson (init.js:230)at Object.json (init.js:187)at s (init.js:192)at c (init.js:76)at d (init.js:76)at b.Deferred.resolve.callback (init.js:77)at init.js:195at k (init.js:199)at m (init.js:199)at f.resolve (init.js:201)

Would anyone know why this error is being thrown and any possible solutions for it?

0 Kudos
4 Replies
New Contributor

When running the following url:http://localhost:(portnumber)/proxy/proxy.ashx?http://(url)/arcgis/rest/services/(ServiceName)/FeatureServer/0/4314 I get the following error:

{error: {code: Forbidden,message:"Proxy is being used for an unsupported service: above url^^)

I don't know if this might help.

0 Kudos
MVP Esteemed Contributor


   Is the url ht tp://(url)/arcgis/rest/services/ added to your proxy.config? Have you tested your proxy to make sure it is still working. 

ht tp://localhost:[portnumber]/proxy/proxy.ashx?ping

0 Kudos
New Contributor

When I added it to the proxy.config and attempted to open the url it took me to the page related to the feature, however when I then clicked on the add attachment button from on that page it told me page not found and I noticed that the url turned into http://localhost:(portnumber)/arcgis/rest/services/(ServiceName)/FeatureServer/0/4314/AddAttachments - it took away the part of the proxy and the host service url.

When I ran the url: http://localhost:24698/proxy/proxy.ashx?ping  I got the following error message: {error: {code: Forbidden,message:"Proxy is being used for an unsupported service: ping"}}

0 Kudos
New Contributor

The following is my config file:
<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="*"
<serverUrl url="" matchAll="true"/>
<serverUrl url="http://localhost/eGIS.API" matchAll="true" />
<serverUrl url="http://localhost:40580" matchAll="true" />
<serverUrl url="http://localhost:41263" matchAll="true" />
<serverUrl url="http://localhost" matchAll="true" />
<serverUrl url="http://localhost:82" matchAll="true" />
<serverUrl url="http://localhost:24698" matchAll="true" />
<serverUrl url="http://url:8030/arcgis/rest/services" matchAll="true" />
<serverUrl url="" matchAll="true" />
<serverUrl url="" matchAll="true" />

0 Kudos