I got the error code 405 resolved. I was referencing portalUrl as this.portalUrl.
But again I am back to the same error, the generate returning a html instead of json response
error - Unexpected token '<'
<div>
<div data-dojo-attach-point="mapNode"></div>
<div>
<form enctype="multipart/form-data" method="post" id="uploadForm">
<div class="field">
<label class="file-upload">
<span><strong>Add File</strong></span>
<input type="file" name="file" id="inFile" />
</label>
</div>
</form>
</div>
</div>
const fileName='';
document
.getElementById("uploadForm")
.addEventListener("change", (event) => {
fileName = event.target.value.toLowerCase();
});
//filepath is from local drive: D:\GIS\tl_2020_39_tabblock20.zip
const portalUrl = "https://www.arcgis.com";
let name = fileName.split(".");
name = name[0].replace("c:\\fakepath\\", "");
var params = {
'name': name,
'targetSR': this.map.spatialReference,
'maxRecordCount': 1000,
'enforceInputFileSizeLimit': true,
'enforceOutputJsonSizeLimit': true
};
var extent = scaleUtils.getExtentForScale(this.map, 40000);
var resolution = extent.getWidth() / this.map.width;
params.generalize = true;
params.maxAllowableOffset = resolution;
params.reducePrecision = true;
params.numberOfDigitsAfterDecimal = 0;
var myContent = {
'filetype': 'shapefile',
'publishParameters': JSON.stringify(params),
'f': 'json'
};
console.log(document.getElementById("uploadForm"));
console.log(dom.byId("uploadForm"));
var layersRequest = esriRequest({
url: portalUrl + "/sharing/rest/content/features/generate",
content: myContent,
handleAs: "json",
form: document.getElementById("uploadForm")
}, { usePost: 'true', });
layersRequest.then(
function (response) {
console.log("Success: ", response.layers);
}, function (error) {
console.log("Error: ", error.message);
});