Hi there,
The error suggests that its not importing esriRequest correctly. Looking at what you have in your import statement, you are trying to import a non-default export by using the {}, esriRequest, is the default export, can you try changing the import statement to
import esriRequest from 'esri/request'
instead of
import {esriRequest} from 'esri/request'
Below is a utils file we have that we use for the GP services that require upload functionality.
import { getAppStore } from "jimu-core";
import esriRequest from "esri/request";
import Geoprocessor from 'esri/tasks/Geoprocessor';
export default class GeoprocessingUtils {
uploadUrl: string;
token: string;
gp: Geoprocessor;
constructor(url: string, isUploadSupported: boolean = false) {
this.token = getAppStore().getState().token;
const serverUrl = getAppStore().getState().portalUrl.replace("portal", "server");
const gpUrl = serverUrl + url + "?token=" + this.token;
this.gp = new Geoprocessor({ url: gpUrl });
if (isUploadSupported) {
const urlArr = url.split("/GPServer/");
this.uploadUrl = (urlArr.length > 1) ? serverUrl + urlArr[0] + "/GPServer/uploads/upload" : "";
} else {
this.uploadUrl = "";
}
}
uploadFile = async (file: any): Promise<string> => {
let form = new FormData();
form.append('file', file);
form.append("f", "json");
form.append("title", file.name);
form.append("name", file.name);
form.append("type", file.type);
form.append("token", this.token);
form.append("filename", file.name);
let upload = await esriRequest(this.uploadUrl, {
method: "post", body: form
}).then(this.uploadSucceeded, this.uploadFailed)
.catch((error) => {
console.error('An error occured uploading the file: ' + error);
return null;
});
if (upload) {
return upload;
} else {
return null;
}
}
executeTaskAsyn = async (params: any): Promise<any> => {
let response = await this.gp.submitJob(params)
.then(async (jobInfo) => {
console.log(jobInfo);
var jobid = jobInfo.jobId;
var options = {
interval: 1500,
statusCallback: function (j) {
console.log("Job Status: ", j.jobStatus);
}
};
return this.gp.waitForJobCompletion(jobid, options).then(async () => {
return this.gp.getResultData(jobid, "result").then((result) => {
return result.value;
}).catch(error => {
console.error(error);
return { "error": "Failed to run geoprocessing task" };
});
});
})
.catch((error) => {
console.error(error)
let errorMessages = error.messages.filter(msg => msg.type === 'error');
//the first error is the error message from gp output parameter
if (errorMessages.length > 0) {
return { "error": errorMessages[0].description }
} else {
return { "error": "Failed to run geoprocessing task" };
}
});
if (response) {
return response;
}
}
uploadSucceeded = (response) => {
var itemID = response["data"]["item"].itemID;
console.log("File upload successful, item ID: ", itemID);
return itemID;
}
uploadFailed = (response) => {
console.log("Failed: ", response);
return null;
}
}
Hope that helps.