[OpenLayers-Users] How to force browser to download a file with a OpenLayers request response

Pavel Iacovlev iacovlev.pavel at gmail.com
Thu Jul 31 14:02:41 PDT 2014


Hello,

Your python script should also send the below, it will force the browse to
download the content.

> Content-Disposition: attachment; filename=file_name.json


If you don't have control over the server you could try HTML5:
http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side

There are a couple of libraries which make this work in older IE too by
using Flash.



On Thu, Jul 31, 2014 at 11:46 PM, VictoriaH <bhudspeth at edac.unm.edu> wrote:

> Hello,
>
> I have OpenLayers request that calls a python function that returns a
> GeoJSON formatted text. I can display the text contents in an alert box,
> but
> would like to instead force the browser to offer the text as a GeoJSON file
> to be downloaded. I would appreciate any help that anyone can offer on how
> to do this...
>
> My python script successfully returns a  "Content-Type: application/json\n"
> text to the browser, and my request and response code look like this so
> far:
>
>                 var PM_request = OpenLayers.Request.GET({
>                     url:'scripts/geoTiff2GeoJSON_edited.py',
>                     callback:processData,
>                     params:coords
>                     //headers:{"Content-Type": "application/json\n"}
>                 });
>
>                 function processData(PM_request) {
>                     var PMjson = new
> OpenLayers.Format.JSON().read(PM_request.responseText);
>                     //console.log(PMjson);
>                     alert("Result is:" + PM_request.responseText);
>                 }
>
>
> I would like to add functionality to the processData function above that
> opens a download window of some sort where once can acquire the GeoJSON
> file...
>
> Thank you,
>
> VickH
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/How-to-force-browser-to-download-a-file-with-a-OpenLayers-request-response-tp5154502.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140801/ea8e8ee7/attachment.html>


More information about the Users mailing list