Link to home
Start Free TrialLog in
Avatar of SidFishes
SidFishesFlag for Canada

asked on

Flash builder 4 FileReference download fails to download

I have some mxml

which is supposed to DL a file on a mouse click

Everything seems to work - path is correct as shown by alert, file exists in path,  save dialog opens with correct file name (renamed by data.recipetitle + '.pdf') except when save dialog closes, no file is downloaded. I have seen that this can be due to

1) sandbox security - flex app is in www.server.com/flex  and files to dl are in 'www.server.com/media/recipes/' so shouldn't be an issue
2) Instantiating the filereference var within the function - not doing that.

<s:ItemRenderer
      name="RecipeThumb"
      xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx">


      <fx:Script>
            
            <![CDATA[
import flash.events.*;
                  import flash.net.FileFilter;
                  import flash.net.FileReference;
                  import flash.net.URLRequest;

      static private var fileToDownload:FileReference =  new FileReference();

                  private function download(event:MouseEvent):void {
                        var request : URLRequest = new URLRequest();
                        request.url = 'http://www.server.com/media/recipes/' + data.recipeid + '.pdf';
                        Alert.show(request.url)
                        request.method = URLRequestMethod.GET;
                        try
                        {
                              fileToDownload.download(request,  data.recipetitle + '.pdf');
                              }
                        catch (error:Error)
                        {
                              Alert.show("Unable to download file.");
                        }
                        }

      ]]>
      </fx:Script>


No errors - just a silent fail.

Any ideas?
Avatar of SidFishes
SidFishes
Flag of Canada image

ASKER

hmmm - ok

if I put the pdf file in the same dir as the swf and change to

 request.url = data.recipeid + '.pdf';

it works... so it's either a path thing or I don't understand the sandbox
 request.url = '/media/recipes/' + data.recipeid + '.pdf';

works as well so ...even though every example I've seen uses absolute paths

request.url = 'http://www.server.com/media/recipes/' + data.recipeid + '.pdf';

it seem only relative ones work??

It could be a problem if you access your application while debugging.

If for example you are working directly on www.server.com and are accessing the page using http://localhost/ then the app will need a crossdomain.xml file in the root of the applications as you are loading content from a domain that is different than the one you loaded your application from (I know that this is not actually a different server, but the flash player can't know that).
So try placing an "allow all" crossdomain.xml file at http://www.server.com/crossdomain.xml and if it works then, this was your issue.

<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

Open in new window

thanks but due to our setup here, I am debugging on our live server (in an IP restricted access section) so the swf and the files are all on the same domain.
Well I would recommend using Firefox with an installed Firebug or Chrome and to activate the developer tools to have a look at what is acutally loaded from where ... I still guess that it's an issue with the security sandbox.
preface this with I've only been working with flash for a while - I come from the Coldfusion world.

I do use FF + FB and have for years but I'm not sure how to use it conjunction with flash. I did install the flashconsole addon for FB but it seems it's only useful if you add trace statements to the code - which I think gives me the same info as the alert dialog -


not seeing any output to firebug when I click my DL link
btw - I did add crossdomain.xml to the root prior to your previous post

I am trying to load the file from

resources.server.com/media/pdfs

with the swf in

www.server.com/flex

using the following

<?xml version="1.0"?>
<cross-domain-policy>
      <allow-access-from domain="*.server.com"/>
</cross-domain-policy>

this file is in d:\server\inetpub\webroot\ (well not actually it's a vDir but it's webroot for the site)




Well my experiance with problems of your type, that they were mainly related to requests not going to the destinations they shoud go. So my suggestion to use FB was intended that way, that you explicitly check which http-requests go to where and what the answers are. This type of debugging has proven to be far more efficient than to debug flex or server-side code in order to resolve problems of your type.
ASKER CERTIFIED SOLUTION
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
aha!

the issue was not the pdf, it was the crossdomain.xml file

I had put it in server.com/webroot

flash was looking for it in resources.server.com/webroot (ie: the "remote" domain)

not sure why as that seems to go against what I've read but maybe I read wrong.

In any case. fixed.

thanks


Yeah ;-) ... as I said ... looking at the http-requests usually halps a lot :-)