When I was trying this, ArcGIS Javascript API wasn't supporting the file upload function yet, which was why it didn't work. I had to switch back to 3.x to proceed with the functionality I needed. I don't know if 4.x has been updated or not yet to include a file upload function, so the below code is 3.x code.
Regardless, this is the code I ended up with. The key is that you assign the itemID to a DataFile object and pass the DataFile object as a parameter to the service. Then get your parameter in python and it will recognize it as a file instead of a nonsensical itemID:
Python code for getting the file and unzipping it. I did not have to do anything with the itemID in here, after assigning the itemID to a DataFile object in JS, it comes in as a zip file instead of an itemID:
uploadedZip = arcpy.GetParameterAsText(0)
try:
zip_ref = zipfile.ZipFile(uploadedZip, 'r')
zip_ref.extractall(scratchFolder)
zip_ref.close()
arcpy.AddMessage("Successfully extracted zip file...")
for file in os.listdir(scratchFolder):
if file.endswith(".gdb") and file != "scratch.gdb":
uploadedGDB = os.path.join(scratchFolder, file)
try:
fcName = "{0}_MgmtTracts_Template".format(stateID)
mgmtTractFC = os.path.join(uploadedGDB, fcName)
JS passing itemID as parameter:
mgmtGP = new Geoprocessor("https://www.stuff.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/HabitatManagement");
function mgmtUpload() {
else {
var upload = esri.request({
url: "https://www.stuff.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/uploads/upload",
form: dojo.byId("mgmtUploadForm"),
content: { f: 'json' },
handleAs: 'json',
}).then(mgmtUploadSucceeded, mgmtUploadFailed);
}
}
function mgmtUploadSucceeded(response) {
var itemID = response["item"].itemID;
var dataFile = new esri.tasks.DataFile();
dataFile.itemID = itemID;
var params = { "Input_Zip_File": dataFile };
console.log('Input parameters: ' + dojo.toJson(params));
mgmtGP.submitJob(params, gpJobComplete, gpJobStatus, function (error) {
console.error('[(jobStatus: ' + gpError.jobStatus + ') (jobId: ' + gpError.jobId + ') ' + '(messages: ' + gpError.messages + ')]');
}).then(function (promiseResult) {
$("#mgmt").button('enable').removeClass('ui-state-disabled');
});
}