Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Flash builder 4 FileReference download fails to download

Posted on 2011-03-10
12
Medium Priority
?
922 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 2000 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
In this article, WatchGuard's Director of Security Strategy and Research Teri Radichel, takes a look at insider threats, the risk they can pose to your organization, and the best ways to defend against them.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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