Hello,
It looks like the FMEServer.runDataStreaming function doesn't quite do what you need it to for your application. It will always return the contents of the file that was created by the workspace. Here are some examples of a couple of different ways to download the file instead.
This will open the file created by the workspace in a new tab (but that new tab will automatically close and the file download dialog for your browser will appear instead).
window.open('http://MYSERVERNAME/fmedatastreaming/MYREPOSITORY/MYWORKSPACE.fmw?token=MYTOKEN')
This opens the file in an invisible iframe element and then the browser will download the file:
var url = 'http://MYSERVER/fmedatastreaming/' + repository + '/' + workspace + '?accept=contents';
url = url + 'opt_showresult=true&token;=' + token + '&' + params;
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.src = url
I hope this helps!
I'll also look into what we can do to add to the functions in the FMEServer javascript library to make this easier to do in the future.
Thanks @LauraAtSafe we did come across that solution prior to posting, but were hoping something could be done using the API.
Cheers :)
@todd_davis see above
Thanks @LauraAtSafe we did come across that solution prior to posting, but were hoping something could be done using the API.
Cheers :)
@todd_davis see above
I see. Thanks for the feedback, @hkingsbury! I think we should be able to either add a new function to the API or update the existing call to the data streaming service and update the javascript library pretty quickly. I'll send you an update when it's done.
Hi,
we struggling with the same problem. We are getting back an excel from our service wuth runDataStreaming but we are unable to handle the response in javascript. We want the response to download to the user but it doesnt seem to be valid blob or dataURL:
Embedding a GET request like shown above doesn`t work because we need to post data to the workspace.
How can we make the response to download to the user?
I've been able now to find a workaround :). Therefore I had to slightly modify the FMEServer.js API file.
in the ajax() function there`s a if/else block to decide xDomain or normal request. In both cases add the following after the req object has been initialized:
req.responseType = 'blob';
Also make sure that you in both cases return the response as blob not as text! So replace
callback(resp)
with
callback(req.response)
Finally you should be able to process the output Blob within the runDataStreaming() API-Method:
FMEServer.runDataStreaming( "YouRepository", "YourWorkspace", "yourParams", function(blob) { var blob = request.response; var a = document.createElement(""a""); a.href = window.URL.createObjectURL(blob); a.download = ""meldungen.xlsx""; a.click(); });