0

我有一个带有文件名的数据网格的 Flash 应用程序,我希望用户能够检查该网格中的多个文件并将它们下载到他的本地驱动器。这些文件存储在数据库中的 blob 字段中,我使用 php ro 检索它们。我试图使用 URLLoader 和 FileReference 来下载文件,但它不起作用。这是代码:

private function downloadSelected():void {
            var dp:Object=dg.dataProvider;
            var cursor:IViewCursor=dp.createCursor();

            while( !cursor.afterLast )
            {

                //Alert.show(cursor.current.IsChecked.toString());
                if (cursor.current.IsChecked.toString()=="true") {
                    //myAmostras.push(cursor.current.CodBarras.toString());
                    //nenhumaAmostra=false; 

                var u:URLRequest= new URLRequest;
                    var variables:URLVariables = new URLVariables();            
                    variables.amostras = cursor.current.CodBarras.toString();
                    variables.disposition="attach";
                    u = new URLRequest("savereports.php");
                    u.method = URLRequestMethod.POST;
                    u.data=variables;


                    pdfloader = new URLLoader();
                    //pdfloader.dataFormat=URLLoaderDataFormat.BINARY;
                    pdfloader.addEventListener(Event.COMPLETE, completeHandler,false,0,true);
                    pdfloader.addEventListener(IOErrorEvent.IO_ERROR, downloadError); 


                    try {
                        pdfloader.load(u);
                    } catch (error:Error) {
                        Alert.show("Unable to load requested document.");
                    }

                }
                cursor.moveNext();
            }   
        }

        private function downloadError(event:Event):void {
            Alert.show("Error loading file");
        }



        private function completeHandler(event:Event):void {

            var myFileReference:FileReference = new FileReference();

            myFileReference.save(event.target.data);

        }

谁可以帮我这个事?

4

1 回答 1

0

使用 FileReference.download 而不是 URLLoader,我可以下载在数据网格中选择的第一个文件,但其他文件抛出异常 Error#2041

        private function downloadSelected():void {
            var dp:Object=dg.dataProvider;
            var cursor:IViewCursor=dp.createCursor();

            var i:int=0;
            while( !cursor.afterLast )
            {
                if (cursor.current.IsChecked.toString()=="true") {

                    var u:URLRequest= new URLRequest;
                    var variables:URLVariables = new URLVariables();            
                    variables.amostras = cursor.current.CodBarras.toString();
                    variables.disposition="attach";
                    u = new URLRequest("savereports.php");
                    u.method = URLRequestMethod.POST;
                    u.data=variables;

                    try {


                        var myFileReference:FileReference = new FileReference();
                        myFileReference.download(u,cursor.current.CodBarras.toString()+".pdf");
                    } catch (error:Error) {
                        Alert.show("Unable to load " + cursor.current.CodBarras.toString()+".pdf" );
                    }

                }
                cursor.moveNext();
            }   
        }
于 2013-03-13T17:56:10.260 回答