Does a Web Service exist that returns a file from POST string

92 views Asked by At

I'm creating a service that produces a driving route from a set of waypoints. Once finished, I need to output a GPX file (basically a XML formatted file with a schema specific to GPS data).

All of my code is in JS, so outputting a file is not straightforward, I know I can write something in PHP, but this complicates things a little for me.

My question is, is there an existing web service where I can simply POST the XML data as a string and it return the file?

Many thanks,

Stu

1

There are 1 answers

2
Thomas Eschemann On BEST ANSWER

You could convert your string to a blob and then use data URLs to "create" a file and download it:

var data = "<test>test</test>";
var blob = new Blob([data], {type : 'text/xml'});

var a = document.createElement('a');
a.download = 'test.xml';
a.href = URL.createObjectURL(blob);

a.dispatchEvent(new MouseEvent('click', {
  view: window,
  bubbles: true,
  cancelable: true
}));

it's a bit hacky but it definitely works.