Error when uploading file to gp service using JavaScript

927
0
01-09-2014 05:33 PM
EdSaunders
Occasional Contributor
Hi all, wondered if anyone can help...

I'm trying to upload a text file to a gp service but it fails.  In the ArcGIS Server logs there is the following error:

Internal Server Error. JSONObject["file"] not found.

I can successfully upload the same text file using the REST endpoint of the service, i.e. http://<server>:6080/arcgis/rest/services/RA/SydneyWaterCompletions/GPServer/uploads/upload, but it fails when trying to upload using the ArcGIS JavaScript API.  My code is below:

dojo.require("esri.utils");
dojo.require("esri.map");
dojo.require("esri.tasks.gp");
dojo.require("dojo.io.iframe");

var gp;
var params;
var sourceFile;
var requestHandle;
var fileName;
var name;
var proxyUrl = "http://<server>/slproxy/proxy.ashx";
var gpUploadURL = "http://<server>:6080/arcgis/rest/services/RA/SydneyWaterCompletions/GPServer/uploads/upload";

esri.config.defaults.io.proxyUrl = proxyUrl;
gp = new esri.tasks.Geoprocessor("http://<server>:6080/arcgis/rest/services/RA/SydneyWaterCompletions/GPServer/SydneyWaterCompletions");

function uploadFile() {

 requestHandle = esri.request({
 url : gpUploadURL,
 form : dojo.byId("uploadForm"),
 content : {
  f : "json"
 },
 handleAs : "text",
 load : function(response, io) {
  alert("Success");
 },
 error : function(error, io) {
  alert(error)
 },
        });
}


And here is my markup:
<div id="content">
  <h2>Sydney Water Completions</h2>
    <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="file" size="50" />
    </form>
    <table>
     <tr class="appThumb">
      <td>
      <input type="button" value="Upload" onclick="uploadFile();">
      </input></td>
     </tr>
    </table>
   </div>


Anyone got any ideas?

Thanks very much,
Ed
0 Kudos
0 Replies