wavded / ogre

ogr2ogr geojson-focused web client
http://ogre.adc4gis.com
MIT License
265 stars 79 forks source link

content-type #75

Closed lcrumbliss closed 3 years ago

lcrumbliss commented 5 years ago

Hi there,

The content-type sent back from the webservice is always "application/zip". It isn't normally an issue from most browsers, but for Safari iOS it seems to be; at least iOS 12. I'm guessing it's a little more strict and if the indicated content-type doesn't actually match the content (for example, if it's CSV or KML in the response body) then iOS makes it just about impossible to do what you want with the response.

var data = "json=%7B%22type%22%3A%22FeatureCollection%22%2C%22features%22%3A%5B%7B%22type%22%3A%22Feature%22%2C%22geometry%22%3Anull%2C%22properties%22%3A%7B%22FID%22%3A%220%22%2C%22NAME%22%3A%22PITTSBURG%22%2C%22STATE%22%3A%2240%22%2C%22COUNTY%22%3A%22121%22%2C%22STATEPLANE%22%3A%22S%22%7D%2C%22id%22%3A0%7D%5D%7D&format=CSV&outputName=pc.csv";

var xhr = new XMLHttpRequest();

xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } });

xhr.open("POST", "https://ogre.adc4gis.com/convertJson"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Accept", "text/csv");

xhr.send(data);

wavded commented 5 years ago

Hey @lcrumbliss . Yeah, that is an issue. The endpoint used to be only shapefiles but later was updated to be any format. It's kind of a mixed bag of what you can get back if another format is supplied. I suppose we could punt and say text/plain if its not a shapefile, knowing that won't always work.

lcrumbliss commented 5 years ago

What about a switch statement returning the appropriate type depending on the output file type?

Shapefile (zip) is taken care of. Maybe it would be possible to glean the the other types from https://www.digipres.org/formats/mime-types// and the ones not listed there can either default to text/plain or application/octet-stream depending.

That's the only way I can think of, really.

wavded commented 5 years ago

What about a switch statement returning the appropriate type depending on the output file type?

The appropriate file type is unknown for most of the types, someone would have to figure out a mapping from every supported ogr2ogr format to a corresponding mime type. Since it is a data stream we can't detect the type based on extension for example.

lcrumbliss commented 5 years ago

Every ogr2ogr supported format or just the subset supported by the ogre webservice?

wavded commented 5 years ago

The Ogre webservice would support whatever the underlying ogr2ogr tool supported which will vary depending on where it is hosted. There are some formats that won't work (like Postgres) because the web API doesn't allow for additional options.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 3 years ago

This issue was closed because it has been stalled for 5 days with no activity.