Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 926
  • Last Modified:

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?
0
SidFishes
Asked:
SidFishes
  • 6
  • 6
1 Solution
 
SidFishesAuthor Commented:
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
0
 
SidFishesAuthor Commented:
 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??

0
 
ChristoferDutzCommented:
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).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ChristoferDutzCommented:
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

0
 
SidFishesAuthor Commented:
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.
0
 
ChristoferDutzCommented:
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.
0
 
SidFishesAuthor Commented:
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
0
 
SidFishesAuthor Commented:
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)




0
 
ChristoferDutzCommented:
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.
0
 
ChristoferDutzCommented:
If you're not seeing anything at all this is a pretty good hint at that flex isn't requesting anything at all from anywhere. So this is a pretty good starting point :)
0
 
SidFishesAuthor Commented:
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


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

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now