Calling a service to download a file does not handle the response, but the service is actually called and returns an http 200

2311
3
Jump to solution
05-11-2016 09:09 AM
MikkelHylden
Occasional Contributor

I have built a web service running locally that will send an excel file back as part of the request.  If I put the URL directly in a browser, I get the file as an attachment as expected. 

http://localhost:6993/api/ExportFile/?inString=urlString&jsonData=urlData

I am trying to call this from a button click that I have added to a customized attribute table.  At this point, I'm not passing 'real' data but simply trying to get the test file to be downloaded in the WAB app.  If I'm running the service in debug, I do hit the breakpoint in the service with the values passed in the following esri.request call.  Fiddler indicates that the call sends back a 200 status, so the service seems to be ok.  The problem is that it seems to die in the esri request side - neither my success nor failure gets handled by the javascript. 

Any ideas on what I need to change in the ESRI Request call would be greatly appreciated.  Note that if I do the export to CSV that is built in to the attribute table that has no problem streaming a file as an attachment. 

          var exportURL = this.config.exporttoexcelservice;

          var list = esriRequest( 

            { 

                url: exportURL,

                //content: { f: "json", "jsonData": this.getCurrentTable() },

                content: { f: "json", "inString": "New Data Value", "jsonData": this.getCurrentTable().grid },

                handleAs: "blob",

                callbackParamName: "callback", 

                timeOut:20000, 

            });

          list.then( 

            //lang.hitch(this,

                function (response) {

                    console.log("Success from Export: ", response);

                }, 

                function(error) { 

                    console.log("Failure on Export: ", error.message);

                }//) 

          );

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MikkelHylden
Occasional Contributor

Update on this - Robert was right in that it was a cross domain issue, since my two localhost apps had different port numbers.  Since my end solution will all be on the same web server though, I just wanted to work around this in testing rather than create a proxy for the dev environment only. 

I found another solution, where I just had to modify the ApplicationHost.config file in my IIS Express settings.  I added the two Access Control lines below to enable cross domain access with my IIS Express, and now the response gets handled normally.

        <httpProtocol>

            <customHeaders>

                <clear />

                <add name="X-Powered-By" value="ASP.NET" />

  <add name="Access-Control-Allow-Origin" value="*" />

  <add name="Access-Control-Allow-Headers" value="Content-Type" />

            </customHeaders>

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Mikkel,

  I don't have any experience requesting a blob. But I have to use a proxy (because of CORs) to get json from one of my web services:

        var requestHandle = esriRequest({
          url: 'my url',
          content: {
            ppin: ppin,
            f: 'json'
          },
          handleAs: "json",
          timeout: 10000
        },{useProxy: true, usePost: false, disableIdentityLookup: true});

        requestHandle.then(lang.hitch(this, function(taxReportJSON){
MikkelHylden
Occasional Contributor

Thanks for the tip.  I'll try to add these sites to the proxy that I use for connecting locally hosted WAB apps through to services in AGOL - at least I'm assuming it's the same one.  I'll let you know how it goes.

0 Kudos
MikkelHylden
Occasional Contributor

Update on this - Robert was right in that it was a cross domain issue, since my two localhost apps had different port numbers.  Since my end solution will all be on the same web server though, I just wanted to work around this in testing rather than create a proxy for the dev environment only. 

I found another solution, where I just had to modify the ApplicationHost.config file in my IIS Express settings.  I added the two Access Control lines below to enable cross domain access with my IIS Express, and now the response gets handled normally.

        <httpProtocol>

            <customHeaders>

                <clear />

                <add name="X-Powered-By" value="ASP.NET" />

  <add name="Access-Control-Allow-Origin" value="*" />

  <add name="Access-Control-Allow-Headers" value="Content-Type" />

            </customHeaders>

0 Kudos