Upload Shapefile error: cannot read property of name

365
0
06-23-2021 08:31 AM
JamesCrandall
MVP Frequent Contributor

js 3.36

Attempting to implement the upload shapefile example into a new custom widget but having an issue on the first attempt (subsequent attempts using a different .zip name works as expected).  Basically on the request({load:}) property it errors with "TypeError: Cannot read property of name of undefined at https://js.arcigs.com.... and just goes to the errorHandler.

//use the rest generate operation to generate a feature collection from the zipped shapefile.  
			     request({
			         url: this.portalUrl + '/sharing/rest/content/features/generate',
			         content: myContent,
			         form: dom.byId('uploadForm'),
			         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;
			             dom.byId('upload-status').innerHTML = '<b>Loaded: </b>' + layerName;
			             this.addShapefileToScratch(response.featureCollection);
                         document.getElementById("inFile").innerHTML = '';
			         }),
			         error: lang.hitch(this, this.errorHandler)
			     }, { usePost: 'true' });
			 },

			 errorHandler: function (error) {
			     dom.byId('upload-status').innerHTML = "<p style='color:red'>" + error.message + "</p>";
			     console.log("errorHandler: ", error.message)
			     document.getElementById("inFile").innerHTML = '';
			 },

 

0 Kudos
0 Replies