Solved

Flash builder 4 FileReference download fails to download

Posted on 2011-03-10
12
896 Views
Last Modified: 2012-05-11
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
Comment
Question by:SidFishes
  • 6
  • 6
12 Comments
 
LVL 36

Author Comment

by:SidFishes
ID: 35100060
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
 
LVL 36

Author Comment

by:SidFishes
ID: 35100098
 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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35107142
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35107157
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
 
LVL 36

Author Comment

by:SidFishes
ID: 35109697
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35109983
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
 
LVL 36

Author Comment

by:SidFishes
ID: 35131845
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
 
LVL 36

Author Comment

by:SidFishes
ID: 35132012
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35132036
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
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 35132045
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
 
LVL 36

Author Comment

by:SidFishes
ID: 35132718
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35132947
Yeah ;-) ... as I said ... looking at the http-requests usually halps a lot :-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AS3 parent function 3 673
Custom Component 1 251
air/as3 : is there a way to simulate TouchEvents? 1 436
To integrate SSRS reports in flex 4.6 6 535
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question