Uploading a shapefile using ArcGIS JavaScript API 4.9 esri/request method?

4079
5
Jump to solution
12-11-2018 09:31 AM
CenterlineMapping
New Contributor III

Does anyone have sample code for uploading a shapefile client side using the 4.9 javascript api and the esri/request method?

Thank you so much.

0 Kudos
1 Solution

Accepted Solutions
MunachisoOgbuchiekwe
New Contributor III

Hello Centerline, 

I was actually working on a sample that takes the 3.x sample of adding shapefiles to the map (Add Shapefile) and converting it to 4.x.  It currently only works when the shapefile has points and not polygons/polylines. I ran into some issues when trying to complete this though...

  • There is currently a bug with esri/request where the query parameters does not get passed to the body when making a POST. To work around this you can use a different request API like Fetch.

Like I have said above, I have a working beta for shapefiles that include points. If you would like to use that as a starting point, feel free to let me know and I can send it to you. 

Also, you mentioned client-side, the sample would need an Portal or ArcGIS Online for this to work since it uses the Generate operation.

EDIT: Looks like I actually got it to work. Here is the link to the code Sample of add shapefile. You do need AGOL or Portal for this to work. Also you may need the resource proxy to remedy any CORS errors you may get. This sample is based on the 3.x, so a lot of the code from that sample is the same with some changes for 4.x.

View solution in original post

5 Replies
MunachisoOgbuchiekwe
New Contributor III

Hello Centerline, 

I was actually working on a sample that takes the 3.x sample of adding shapefiles to the map (Add Shapefile) and converting it to 4.x.  It currently only works when the shapefile has points and not polygons/polylines. I ran into some issues when trying to complete this though...

  • There is currently a bug with esri/request where the query parameters does not get passed to the body when making a POST. To work around this you can use a different request API like Fetch.

Like I have said above, I have a working beta for shapefiles that include points. If you would like to use that as a starting point, feel free to let me know and I can send it to you. 

Also, you mentioned client-side, the sample would need an Portal or ArcGIS Online for this to work since it uses the Generate operation.

EDIT: Looks like I actually got it to work. Here is the link to the code Sample of add shapefile. You do need AGOL or Portal for this to work. Also you may need the resource proxy to remedy any CORS errors you may get. This sample is based on the 3.x, so a lot of the code from that sample is the same with some changes for 4.x.

CenterlineMapping
New Contributor III

Hello Munachiso,

Thank you kindly for your feedback.  We are working with polygons so that is good to know.  Also, we did notice the query parameter issue.  We have AGOL and Portal access.  I will take a look at your sample and also the Fetch API and see if this will get working.  Thanks again for your feedback.  

0 Kudos
CenterlineMapping
New Contributor III

UPDATE:  Munachiso, were you able to get it to work for polygons?  Thanks again.

0 Kudos
MunachisoOgbuchiekwe
New Contributor III

Yes, I have updated the sample and it should work with polygons and polylines. 

CenterlineMapping
New Contributor III

Thanks Munachiso, I appreciate your expertise.  

0 Kudos