ArcGIS REST API Generate VS Esri Request

364
0
10-07-2019 09:57 AM
AlbertoLópez
New Contributor III

Hello;

I am using esri request in a web application with VERSION  3.8 of the API ArcGIS Javascipt to add  a shapefile (https://developers.arcgis.com/javascript/3/jssamples/portal_addshapefile.html)

The application gives the following error:

This is the Network tab in Chrome:

This is my function:

generateFeatureCollection: function (fileName) {
 
  var name = fileName.split(".");
  name = name[0].replace("c:\\fakepath\\", "");
 
  var params = {
  'name': name,
  'targetSR': this.activeMainMap.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',
   'callback.html': 'textarea'
  };

  var portalUrl= 'http://www.arcgis.com';
 
  esriRequest({
     url: portalUrl + '/sharing/rest/content/features/generate',
     content: myContent,
     form: dom.byId('uploadFormCargaRodales'),
     handleAs: 'json',
     load: lang.hitch(this, function (response) {
     
    if (response.error) {
       console.log("response.error: ", response.error)
       this.errorHandler(response.error);
      return;
    }
   var layerName = response.featureCollection.layers[0].layerDefinition.name;
   this.addShapefileToMap(response.featureCollection);
 }),
 error: lang.hitch(this, this.errorHandler)
 }, 
 {usePost:true}); 
 
},‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is my html:

 

<form enctype="multipart/form-data" method="post" id="uploadFormCargaRodales">
          <input type="file" name="file" id="inFile" />
</form>‍‍‍‍‍‍‍‍‍‍‍‍

 

 

The error occurs in esriRequest.

I have read this but without results:

https://community.esri.com/thread/213470-arcgis-rest-api-generate

and  this:

https://stackoverflow.com/questions/23784920/im-getting-unexpectected-token-for-a-valid-json

 

I've tried also with esri.request (v 3.8) but without results too.

If you change 3.29 by 3.8 in this example https://developers.arcgis.com/javascript/3/jssamples/portal_addshapefile.html happen my error (unexpected token <)

Any suggestions?

Thank you very much, greetings.

Tags (1)
0 Kudos
0 Replies