Code Monkey home page Code Monkey logo

Comments (5)

zhengniu avatar zhengniu commented on September 3, 2024

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 = $('<iframe/>',{'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);

from ogre.

zhengniu avatar zhengniu commented on September 3, 2024

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);
        }
    }
});

from ogre.

wavded avatar wavded commented on September 3, 2024

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.

from ogre.

zhengniu avatar zhengniu commented on September 3, 2024

Thank you so much. it is working well.

is it possible to host the similar service locally?

from ogre.

wavded avatar wavded commented on September 3, 2024

yes, the readme has instructions, there also is a Dockerfile included in the project if you want to build it that way.

from ogre.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.