Hello,
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 = "https://myserver.com/arcgis/rest/services/ImportFileToGDB/GPServer/ImportFileToGDB";
var fileUploadUrl = "https://myserver.com/arcgis/rest/services/ImportFileToGDB/GPServer/uploads/upload";
document
.getElementById("uploadForm")
.addEventListener("change", function(event) {
var fileName = event.target.value.toLowerCase();
if (fileName.indexOf(".zip") !== -1) {
uploadFile(fileName);
} 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) {
var upload = esriRequest(
fileUploadUrl,
{
body: document.getElementById("uploadForm"),
method: "post",
responseType: "json"
}
).then(uploadSucceeded, errBack);
}
function uploadSucceeded(result) {
document.getElementById("upload-status").innerHTML = "File uploaded"
var itemID = result.item.itemId;
var dataFile = new DataFile();
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 + "'";
console.log(value.jobStatus);
}
function handleResult(result) {
document.getElementById("upload-status").innerHTML = "Success";
console.log('here');
}
function errBack(error) {
document.getElementById("upload-status").innerHTML = "Error: " + error;
console.log("gp error: ", error);
}
});
Regards,
Mark