AnsweredAssumed Answered

Javascript 4 & Geoprocessing Service with File Upload

Question asked by MDonnellyesriaustralia-com-au-esridist Employee on Sep 17, 2019
Latest reply on Oct 17, 2019 by MDonnellyesriaustralia-com-au-esridist



I have created a geoprocessing service, with upload enabled, that takes a file as a parameter. I am attempting to call this service from a web application created using Javascript 4.12, however, I have a problem.


The first problem happens when I use the esri request module to transact with the service's upload endpoint. The response will always be returned as html rather than JSON. If I nominate the responseType as "json" I get an error saying there was an unexpected character '<'. If I nominate the responseType as "text" the request succeeds but the response is in html.



        var gpUrl =  "";
        var fileUploadUrl =  "";

          .addEventListener("change", function(event) {
            var fileName =;

            if (fileName.indexOf(".zip") !== -1) {
              //is file a zip - if not notify user
            } else {
              document.getElementById("upload-status").innerHTML =
                'Add shapefile as .zip file';

        var gp = new Geoprocessor(gpUrl);

        var fileForm = document.getElementById("mainWindow");

        var expand = new Expand({
          expandIconClass: "esri-icon-upload",
          view: view,
          content: fileForm

        view.ui.add(expand, "top-right");
        function uploadFile(fileName) {
            //upload the zip file and get back the itemID (via uploadSucceeded)
            var upload = esriRequest(
                    body: document.getElementById("uploadForm"),
                    method: "post",
                    responseType: "json"/*,
                    headers: {"Content-Type": "application/json"}*/

            ).then(uploadSucceeded, errBack);


        function uploadSucceeded(result) {
          document.getElementById("upload-status").innerHTML = "File uploaded"
          var itemID = result.item.itemId;
          //Create the DataFile object you will assign your itemID to
          var dataFile = new DataFile();
          //The itemID points to the zip file, which is why I assign it the dataFile object
          dataFile.itemID = itemID;
          var params = {
             "Import_File": dataFile

          gp.submitJob(params).then(handleResult, errBack, progTest);
        function progTest(value) {
          document.getElementById("upload-status").innerHTML = "Job status: " + "'" + value.jobStatus + "'";
        function handleResult(result) {

            //Handle the querying, zooming and opening the FeatureForm
            document.getElementById("upload-status").innerHTML = "Success";
        function errBack(error) {
          document.getElementById("upload-status").innerHTML = "Error: " + error;
          console.log("gp error: ", error);