span8
span4
span8
span4
Hi All
I've built a workbench that generates an Excel file.What the end goal is to have this work bench accessible through a web page and allow the user to download the result as a .xlsx (not a zipped .xlsx).
I've tried two ways to get this working:
Any one have any thoughts on how this can be fixed?
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.
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)
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();});
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?
Thanks@LauraAt亚搏在线Safewe did come across that solution prior to posting,but were hoping something could be done using the API.
Cheers :)
@todd_davissee above
© 2019 亚搏在线Safe Software Inc |Legal