Closed zhengniu closed 9 years ago
Hi Wavded,
I try another way to create Post request like below, but it can not find the path of zip file,
var parameters ={ json:GeoJson, outputName:"zippedshp.zip" } var options ={ url:"http://ogre.adc4gis.com/convertJson", type: "POST", data: parameters, contentype:"application/zip", success:function(data){ if(data){ console.log(data.path); if(data.path) { //Create an hidden iframe, with the 'src' attribute set to the created ZIP file. var dlif = $('',{'src':data.path}).hide(); //Append the iFrame to the context this.append(dlif); } else if (data.error){ alert (data.error); } else{ alert ("Somthing wrong"); } } }
}
$.ajax(options);
hi Waveded,
I find one solution can download the zipped shapefile through Post request , as shown below. however, the download zip file can not be used due to : Windows cannot open the folder. The compressed (zipped) Folder 'C:\Users\niuzh\Downloads\zippedshp(6).zip' is invalid.
Thanks for your comments.
var params ={
json:GeoJson,
outputName:"zippedshp.zip"
}
$.ajax({
url:'http://ogre.adc4gis.com/convertJson',
type: "POST",
data: params,
success: function(response, status, xhr) {
var filename = "zippedshp";
var type = xhr.getResponseHeader('Content-Type');
var blob = new Blob([response], { type: type });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(blob, filename);
}
else {
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);
//console.log(downloadUrl);
if (filename){
var a = document.createElement("a");
if (typeof a.download === 'undefined') {
window.location = downloadUrl;
}
else {
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
}
}
else {
window.location = downloadUrl;
}
setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100);
}
}
});
I am not up to speed on latest browser file handling but my current understanding is that you cannot trigger a download from an AJAX request. I believe you want to create a hidden form and submit that to get the download behavior.
Thank you so much. it is working well.
is it possible to host the similar service locally?
yes, the readme has instructions, there also is a Dockerfile
included in the project if you want to build it that way.
Thanks for sharing this great tool
I have tried to use Post request in my code to get zipped file download through web client, but no clue how to do it in callback function to fullfil the same ability as the convert button "Convert to Shapefile" does.
Could you please provide newbies some help? Many Thanks