-
-
Save pingyangtiaer/8c19d9b0d3078d4a555fa0e394dea350 to your computer and use it in GitHub Desktop.
Upload file to Geoprocessing Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> | |
<title>Upload Proxy Issue</title> | |
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css"> | |
<style> | |
html, body, #map { | |
height: 100%; | |
width: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
body { | |
background-color: #FFF; | |
overflow: hidden; | |
font-family: "Trebuchet MS"; | |
} | |
</style> | |
<script src="http://js.arcgis.com/3.8/"></script> | |
<script> | |
var map, gpTask; | |
require(["esri/urlUtils","esri/map", "esri/tasks/Geoprocessor", "esri/arcgis/utils", "esri/request", "dojo/dom", "dojo/on", "dojo/domReady!"], function(urlUtils, Map, Geoprocessor, arcgisUtils, esriRequest, dom, on) { | |
map = new Map("map", { | |
basemap: "topo", | |
center: [-122.45,37.75], // long, lat | |
zoom: 13, | |
sliderStyle: "small" | |
}); | |
urlUtils.addProxyRule({ | |
urlPrefix : "http://sampleserver6.arcgisonline.com/arcgis/rest/services", | |
proxyUrl : "proxy.php" | |
}); | |
//esriConfig.defaults.io.proxyUrl = "proxy.php"; | |
//esriConfig.defaults.io.alwaysUseProxy = true; | |
on(dom.byId("upload"), "click", upload); | |
function upload() | |
{ | |
var upload = esriRequest({ | |
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/uploads/upload", | |
form: dojo.byId("uploadForm"), | |
content: { f: "pjson" }, | |
handleAs: "json", | |
load: displayResult, | |
error: uploadFailed | |
}); | |
//upload.then(uploadSucceeded, uploadFailed); | |
} | |
function uploadSucceeded(response, io) { | |
var itemID= response["item"].itemID; | |
//alert(itemID) | |
var params= { "uploadSHPFile": "{'itemID':" + itemID + "}" }; | |
gpTask = new Geoprocessor("http://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/uploads/upload"); | |
gpTask.setOutSpatialReference({wkid:102100}); | |
gpTask.execute(params, displayResult, errorGP); | |
} | |
function uploadFailed(){ | |
alert("Failed!") | |
} | |
function displayResult(evt) { | |
alert("succeed"); | |
console.log(evt); | |
} | |
function errorGP(){ | |
//alert("fail"); | |
} | |
/*gp = new Geoprocessor("http://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/uploads/upload"); | |
var dataFile = new esri.tasks.DataFile(); | |
dataFile.url = "http://upload.wikimedia.org/wikipedia/commons/4/49/Kap_Sounion.jpg"; | |
var params = { "Input_File": dataFile }; | |
gp.submitJob(params);*/ | |
}); | |
</script> | |
</head> | |
<body> | |
<form id="uploadForm" method="post" enctype="multipart/form-data"> | |
<input type="file" name="file" /> | |
<input type="hidden" name="description" /> | |
</form> | |
<input type="button" value="Upload" id="upload"/> | |
<div id="map"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment