How to upload a CSV to a web service?

4167
4
09-11-2015 09:47 AM
MichaelKozub
New Contributor II

I thought this would be a good place to figure out how to set up a web service to accept a CSV as an input. To keep it short, I want a user to upload a CSV file with lat/long pairings, and the tool will perform a spatial join and give the user the joined fields in an excel spreadsheet. I already have a script tool that works perfectly, but I cannot figure out how to set up a web service to do this.

Currently the (successful) script tool has two parameters: input and output, both of which are File Data Types. Any suggestions on the best way to go about creating a web service to perform this?

0 Kudos
4 Replies
RebeccaStrauch__GISP
MVP Emeritus

Do you have access to ArcGIS Server? If so, I would try to set it up as a geoprocessing service.  What is a geoprocessing service?—Documentation (10.3 and 10.3.1) | ArcGIS for Server  and then look at sharing it with you AGOL account About sharing services with your ArcGIS organization—Documentation (10.3 and 10.3.1) | ArcGIS for Se...

If you do not have access to AGS, I'm not sure, but I'm sure others will know if/how it is done.

0 Kudos
MichaelKozub
New Contributor II

Thanks Rebecca. I do have access to ArcGIS Server and I have created a GP service with this script tool. I just haven't been able to figure out the proper way to allow CSV uploads. It seems that setting the input parameter is where my issue lies.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Michael,

Wish I could help more, but I'm away from my server for another week, so anything more would be speculation. But I am interested in the topic so will follow and jump in if/when I can think of anything more.  Is it possible to share your script?

0 Kudos
MichaelKozub
New Contributor II
import arcpy

inputTable = arcpy.GetParameter(0)

#When running in the python window in ArcMap, I comment out line 3 above and un-comment line 6.  
#inputTable = "C:\\Users\\user1\\Desktop\\example.csv"

arcpy.MakeXYEventLayer_management(inputTable, "Longitude", "Latitude", "tableXY")

arcpy.FeatureClassToFeatureClass_conversion("tableXY", "%scratchfolder%\\Scratch.gdb\\", "tableXYfc")

arcpy.SpatialJoin_analysis("%scratchfolder%\\Scratch.gdb\\tableXYfc", "Database Connections\\example.sde\\example.polygons", "in_memory\\_join","","")

arcpy.TableToExcel_conversion("in_memory\\_join", "C:\\Users\\user1\\Desktop\\final_export.xls")

Here's the script which (which works perfectly in ArcMap).