Skip to main content

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:

  1. DataDownload

     

    This works however the .xlsx is returned in a .zip
  2. DataStreamer

     

    This method works when running the workbench from FME Server (a download window appears) but when using the JS API you simple get the .xlsx return as a string (like if you tried to open a .xlsx file with notepad). Myself and a colleague have tried a number of ways to get this working by playing with the parameters (specifically opt_response format).

     

    I've included the JS in its current state below...

     

     

        <script type="text/javascript">
        var repository, workspace

            window.onload = function() {
                FMEServer.init({
                server : "https://*******************",
                    token : "********************************"
                });

                repository = '***************'
                workspace = "EXCEL_Download.fmw"
            }

            function getData (){
                var PIDs = document.getElementById('projectID').value
                FMEServer.runDataStreaming(repository, workspace, 'opt_responseformat=xlsx&ProjectIDs;='+PIDs, success)

            }
             function success (result){
                 console.log(result)
                 //var url = result.serviceResponse.url
                 //window.open(result, "_parent")
             }

        </script>    

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. 


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();    });


Reply