Solved

Flash builder 4 FileReference download fails to download

Posted on 2011-03-10
12
876 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Flex Air Internet connectivity 5 538
Deleting Objects in flex 1 357
flex - list item renderer 7 669
adobe air 1 285
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…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now