Uploads capability on Geoprocessor

4390
3
Jump to solution
08-07-2012 09:22 AM
DanielBradshaw
New Contributor
Is there supposed to be an uploads capability as part of the geoprocessor class?  The REST enpoint exposes this functionality, but I can't find this capability within the API.  Am I missing something?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DasaPaddock
Esri Regular Contributor
You can use the Flash API to upload a file. Here's sample code for this.

FileReference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#uplo...

REST API reference:
http://resources.arcgis.com/en/help/rest/apiref/upload_item.html

The DataFile also has an itemID property you can set to reference the uploaded file in a GP request:
http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tasks/supportClasses/DataFile.html#...

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">      <fx:Script>         <![CDATA[             import com.esri.ags.utils.JSONUtil;              import mx.controls.Alert;             import mx.utils.ObjectUtil;              private var fileReference:FileReference;              private var timer:Timer;             private var baseTimer:int;              private function onLoad():void             {                 //Instantiate on loading                 fileReference = new FileReference();                  //create the filter which will be just uploading the txt                 var myFilter:FileFilter = new FileFilter("Zip", "*.zip");                 fileReference.browse([ myFilter ]);                 fileReference.addEventListener(Event.SELECT, onFileSelect);                 fileReference.addEventListener(Event.COMPLETE, onFileComplete);                 fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData);                  timer = new Timer(1000);                 timeElapsed.visible = timeElapsed.includeInLayout = true;                 timer.addEventListener(TimerEvent.TIMER, updateTimer);             }              private function onFileSelect(event:Event):void             {                 var fileUploadRequest:URLRequest = new URLRequest("http://server/arcgis/rest/services/ServiceName/GPServer/uploads/upload");                 fileUploadRequest.method = URLRequestMethod.POST;                 var urlVars:URLVariables = new URLVariables();                 urlVars.f = "json";                 urlVars.description = "this is just a test upload";                 fileUploadRequest.data = urlVars;                 fileReference.upload(fileUploadRequest, "file");                  baseTimer = getTimer();                 timeElapsed.visible = timeElapsed.includeInLayout = true;                 timer.start();             }              private function onFileComplete(event:Event):void             {                 timer.stop();                 timeElapsed.visible = timeElapsed.includeInLayout = false;             }              private function updateTimer(event:TimerEvent):void             {                 timeElapsed.text = "TimeElapsed: " + new Date(getTimer() - baseTimer).seconds + "secs";             }              private function onUploadCompleteData(event:DataEvent):void             {                 var result:Object = JSONUtil.decode(event.data);                 Alert.show(ObjectUtil.toString(result), "upload completed - " + result.item.itemID);             }         ]]>     </fx:Script>      <s:Panel id="myPanel"              width="500" height="500">         <s:VGroup>             <s:Button click="onLoad()" label="Upload"/>             <s:Label id="timeElapsed"                      includeInLayout="false"                      visible="false"/>         </s:VGroup>     </s:Panel>  </s:Application>

View solution in original post

0 Kudos
3 Replies
DasaPaddock
Esri Regular Contributor
You can use the Flash API to upload a file. Here's sample code for this.

FileReference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#uplo...

REST API reference:
http://resources.arcgis.com/en/help/rest/apiref/upload_item.html

The DataFile also has an itemID property you can set to reference the uploaded file in a GP request:
http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tasks/supportClasses/DataFile.html#...

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">      <fx:Script>         <![CDATA[             import com.esri.ags.utils.JSONUtil;              import mx.controls.Alert;             import mx.utils.ObjectUtil;              private var fileReference:FileReference;              private var timer:Timer;             private var baseTimer:int;              private function onLoad():void             {                 //Instantiate on loading                 fileReference = new FileReference();                  //create the filter which will be just uploading the txt                 var myFilter:FileFilter = new FileFilter("Zip", "*.zip");                 fileReference.browse([ myFilter ]);                 fileReference.addEventListener(Event.SELECT, onFileSelect);                 fileReference.addEventListener(Event.COMPLETE, onFileComplete);                 fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData);                  timer = new Timer(1000);                 timeElapsed.visible = timeElapsed.includeInLayout = true;                 timer.addEventListener(TimerEvent.TIMER, updateTimer);             }              private function onFileSelect(event:Event):void             {                 var fileUploadRequest:URLRequest = new URLRequest("http://server/arcgis/rest/services/ServiceName/GPServer/uploads/upload");                 fileUploadRequest.method = URLRequestMethod.POST;                 var urlVars:URLVariables = new URLVariables();                 urlVars.f = "json";                 urlVars.description = "this is just a test upload";                 fileUploadRequest.data = urlVars;                 fileReference.upload(fileUploadRequest, "file");                  baseTimer = getTimer();                 timeElapsed.visible = timeElapsed.includeInLayout = true;                 timer.start();             }              private function onFileComplete(event:Event):void             {                 timer.stop();                 timeElapsed.visible = timeElapsed.includeInLayout = false;             }              private function updateTimer(event:TimerEvent):void             {                 timeElapsed.text = "TimeElapsed: " + new Date(getTimer() - baseTimer).seconds + "secs";             }              private function onUploadCompleteData(event:DataEvent):void             {                 var result:Object = JSONUtil.decode(event.data);                 Alert.show(ObjectUtil.toString(result), "upload completed - " + result.item.itemID);             }         ]]>     </fx:Script>      <s:Panel id="myPanel"              width="500" height="500">         <s:VGroup>             <s:Button click="onLoad()" label="Upload"/>             <s:Label id="timeElapsed"                      includeInLayout="false"                      visible="false"/>         </s:VGroup>     </s:Panel>  </s:Application>
0 Kudos
DanielBradshaw
New Contributor
Thanks Dasa - Is there plans to formalize this into the API at some point?  I was watching a screencast from the 2012 Dev Summit and the presenter made a comment inferring as much.
0 Kudos
meriyalootka
New Contributor III
Is there supposed to be an uploads capability as part of the geoprocessor class?  The REST enpoint exposes this functionality, but I can't find this capability within the API.  Am I missing something?


Hy
I have a model for uploading datafile, every thing is ok and user's zip file extract correctly. But I can not use extracted shapefile. Is there any py code for using feature class in a scratchfolder? Can I have this part of your model?
0 Kudos