Upload File to ArcGIS Server

10071
4
04-18-2013 07:58 AM
ZacharyHart
Regular Contributor
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.
0 Kudos
4 Replies
ZacharyHart
Regular Contributor
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.


OK, a bump and a bit of other information: I see that that the REST API supports an upload operation, but I have no idea how to incorporate this into a GP Service, or if that's even possible.
0 Kudos
KevinHibma
Esri Regular Contributor
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>
0 Kudos
MahdiKefayati
New Contributor II

Kevin Hibma

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);

}

0 Kudos
ZacharyHart
Regular Contributor
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>



Yes thanks for that. I've been using this as the initial step to getting the file to the server. After that I have other plans for that file, so using python i'm able to copy it out of the server temp location. Flex is the application though, not desktop.
0 Kudos