Yes, its just as simple as that! While I see that GP services support 'Upload' I've yet to see an example where the user input is data local to their system. I just want to create a simply tool which copies a table from the user's local system and places it in a known location on the server. The service will then run another batch file/executable which takes the table as an input for another function.
Is there anyway to do this without needing to FTP the file up to the server?
EDIT: Clients are web-based, not desktop.
var gpUploadURL = "http://gizmo:6080/arcgis/rest/services/ConvertCSVKriging/GPServer/uploads/upload"; //upload the zip file and get back the itemID (via uploadSucceeded) var requestHandle = esri.request({ url: gpUploadURL, form: dojo.byId("uploadForm"), content:content, load: uploadSucceeded, error: uploadFailed }); function uploadSucceeded(response) { var itemID = response["item"].itemID; //submit the GP Task by passing the itemID info the input parameter var params = {'Input_Rows': "{'itemID':" +itemID+ "}" }; gp.submitJob(params, gpJobComplete, gpJobStatus, function(error){ alert(error); }); } <form id="uploadForm" style='padding:4px;' method="post" enctype="multipart/form-data"> <!-- must use name="file" as Upload expects this --> <input type="file" name="file" id="inFile" size="50" onchange="uploadFile();"/> </form>
How would this change if I am using proxy.
This sample that you have used does not work, even without a proxy. Can you please post a minimally "working" sample?
I get error 400 on the following uploader code:
function uploadFile( svcName, form , uploadSucceeded, uploadFailed){
gpUploadURL = "http://"+gisServer+":6080/arcgis/rest/services/"+svcName+"/GPServer/uploads/upload";
console.log('Uploading file...', gpUploadURL);
esri.request({
url: gpUploadURL,
form: dojo.byId(form),
//callbackParamName: "callback",
content: { f: "jsonp" },
handleAs : "json",
}/*,{usePost: true, useProxy:true}*/).then(uploadSucceeded, uploadFailed);
}
Upload is new at 10.1.
Its a capability you can enabled on the GP Service itself. Doing this allows you to upload a file to the REST end point, and then the service can consume that file. Using this you dont have to write you own "uploader". Keep in mind if you're using this its for simple files: like a text file, or zip - it isn't meant for something like a shapefile or filegeodatabase (structures that are many files comprising 1 file)
If you're using ArcMap as a client - upload doesn't really matter. ArcMap is a rich client which can send a file to gp service. If you're using a web client, see the code below (javascript) which shows how to leverage the upload capability.var gpUploadURL = "http://gizmo:6080/arcgis/rest/services/ConvertCSVKriging/GPServer/uploads/upload"; //upload the zip file and get back the itemID (via uploadSucceeded) var requestHandle = esri.request({ url: gpUploadURL, form: dojo.byId("uploadForm"), content:content, load: uploadSucceeded, error: uploadFailed }); function uploadSucceeded(response) { var itemID = response["item"].itemID; //submit the GP Task by passing the itemID info the input parameter var params = {'Input_Rows': "{'itemID':" +itemID+ "}" }; gp.submitJob(params, gpJobComplete, gpJobStatus, function(error){ alert(error); }); } <form id="uploadForm" style='padding:4px;' method="post" enctype="multipart/form-data"> <!-- must use name="file" as Upload expects this --> <input type="file" name="file" id="inFile" size="50" onchange="uploadFile();"/> </form>