Select to view content in your preferred language

Problem on passing the input file to Geoprocessing service

5047
6
10-14-2012 11:15 PM
sobarim-amin
Emerging Contributor
All,

Kindly advice on my problem.
I created a geoprocessing tool and published it to ArcGIS server.
But since the input for the tool is a datafile, it always failed to get the input.
I am using filereference class to upload the file, but when it passed the datafile.url doesn't seems to be succesfull.

See below code I use to upload the file.

               request = new URLRequest("http://myserver/arcgisoutput/TestNewLine2.txt")
try
{
  fileRef.upload(request);
}
                 catch (error:Error)
{
  trace("Unable to upload file.");
}   


regards,
Sobari
Tags (2)
0 Kudos
6 Replies
IvanBespalov
Frequent Contributor
0 Kudos
sobarim-amin
Emerging Contributor
http://forums.arcgis.com/threads/64114-Uploads-capability-on-Geoprocessor?highlight=upload


Thanks Ivan,

But how can I pass the uploaded file as GP parameter which has input type as GPDataFile  ?

This is what I tested, but does not work

private function onUploadCompleteData(event:DataEvent):void
{      
   try
     {         
gp.execute(event.data);
     }
catch (error:Error)
    {
Alert.show("gpExecute error \n" + error.message );
    }
}


Please advice

Regards,
Sobari
0 Kudos
IvanBespalov
Frequent Contributor
From ESRI help (find GPDataFile😞

import com.esri.ags.events.GeoprocessorEvent;
import com.esri.ags.tasks.Geoprocessor;
import com.esri.ags.tasks.supportClasses.DataFile;
import com.esri.ags.tasks.supportClasses.JobInfo;
import com.esri.ags.utils.JSONUtil;

import mx.rpc.AsyncResponder;
import mx.rpc.Fault;

private function submitJob():void
{
 var gpUrl:String = "http://server/arcgis/rest/services/folder/service/GPServer";
 var gp:Geoprocessor = new Geoprocessor(gpUrl);
 
 var dataFile:DataFile = new DataFile("http://server/folder/file.txt");
    
 var gpParams:Object = new Object();
        gpParams["Input_Data_File_Parameter_Name"] = JSONUtil.encode(dataFile);
 /* wrong
         gpParams["Input_Data_File_Parameter_Name"] = dataFile.toJSON();
         */
 // add other req. parameters
    
 // if service is Asynchronous
 gp.submitJob(gpParams, new AsyncResponder(onJobComplete, onJobFault));
 // else
 gp.addEventListener(GeoprocessorEvent.EXECUTE_COMPLETE, onExecuteComplete);
 gp.execute(gpParams);
}
   
/**
 * Listen job complete server response
 */
protected function onJobComplete(result:JobInfo, token:Object = null):void
{
 if (result.jobStatus == JobInfo.STATUS_SUCCEEDED)
 {
  //TODO: complete code
 }
 else
 {
  //TODO: complete code
 }
}
   
/**
 * Listen server error responses
 */
protected function onJobFault(fault:Fault, token:Object = null):void
{
 trace(fault.message.toString());
}
   
/**
 * Listen job complete server response
 */
protected function onExecuteComplete(event:GeoprocessorEvent):void
{
 //TODO: complete code
}
0 Kudos
sobarim-amin
Emerging Contributor
Hi ibespalov ,

Thanks for your great help..
things is now progressing

But I still have problem:

on dataFile.toJSON, toJSON is not being recognised so I omit toJSON.

when it submit the job,after it process for a few seconds  i received esriJobFailed message (onJobComplete)

Appreciate your advice

Regards,
Sobari
0 Kudos
IvanBespalov
Frequent Contributor
I was wrong. Haste. 🙂
But you could also read the help. :cool:

try it:
gpParams["Input_Data_File_Parameter_Name"] = com.esri.ags.utils.JSONUtil.encode(dataFile);


IMHO, the best practice is testing your service in browser (REST API) at first. Most of browsers comes with "network monitoring tools" (usually F12 key pressing).
Open your GP service, set input parameters - find request in monitoring console ... If your service works - start playing with web APIs.
Good luck.
0 Kudos
sobarim-amin
Emerging Contributor
ibespalov,

As you suggested, I tested the service in browser (REST API), and this was the error I got.

Job ID: jbd6e30cce4654fa48c9272092d21573d
Job Status: esriJobFailed
Job Messages:
esriJobMessageTypeInformative: Submitted.
esriJobMessageTypeInformative: Executing...
esriJobMessageTypeError: ERROR 000840: The value is not a Text File.
esriJobMessageTypeInformative:
esriJobMessageTypeError: ERROR 000840: The value is not a Text File.
esriJobMessageTypeError: Failed.

I was uploading a text file but why the error says "The value is not a Text File. "
Does the text file changed to ZIP file when it uploaded to server using fileReference in flex?
0 Kudos