ActionScript中的File.upload不会对空气SDK工作的iOS设备对空、设备、工作、File

2023-09-09 21:40:44 作者:冷色 cheeks -◢

我想使用ActionScript的File.upload上传的iOS环境空气SDK文件,但File.upload不能正常工作。有关文件上传File.upload执行后没有处理程序被调用,并没有异常被捕获。当我检查服务器端的网络流量,我发现,在执行File.upload后无http请求连撞服务器。在code是如下。

I am trying to use ActionScript's File.upload to upload a file on Air SDK for iOS environment, but the File.upload does not work properly. No handler about the file upload is executed after File.upload is invoked, and no exception is caught. When I check the network traffic of the server side, I found that no http request even hit the server after executing File.upload. The code is below.

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[

            private var file:File;
            private var dir:File;

            //This method is executed to create a file and upload it when the Upload Button is pressed. 
            protected function OnUploadButtonPressed(event:MouseEvent):void{
                trace("upload button clicked");

                var urlReq:URLRequest = new URLRequest("http://10.60.99.31/MyPath/fileUploadTest.do");
                urlReq.method = URLRequestMethod.POST;

                var str:String = 'This is test';

                var imageBytes:ByteArray = new ByteArray();
                for ( var i:int = 0; i < str.length; i++ ) {
                    imageBytes.writeByte( str.charCodeAt(i) );
                }

                trace("size = " + imageBytes.length);

                try{
                    dir = File.applicationStorageDirectory
                    //I also tested in several different directories
                    //dir = File.createTempDirectory();
                    //dir = File.documentsDirectory;
                    var now:Date = new Date();
                    var filename:String = "IMG" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds + now.milliseconds + ".txt";
                    file = dir.resolvePath( filename );
                    var stream:FileStream = new FileStream();
                    stream.open( file, FileMode.WRITE );
                    stream.writeBytes( imageBytes );
                    stream.close();

                    //Read back the file contents to check whether the file is written successfully.
                    var readStream:FileStream = new FileStream();
                    readStream.open(file, FileMode.READ);
                    var result:String = readStream.readUTFBytes(readStream.bytesAvailable);
                    trace("read back result = " + result);//The result is shown here as expected.

                    file.addEventListener( Event.COMPLETE, uploadComplete );
                    file.addEventListener( IOErrorEvent.IO_ERROR, ioError );
                    file.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityError );
                    file.addEventListener(ErrorEvent.ERROR, someError);
                    file.addEventListener(ProgressEvent.PROGRESS, onProgress);


                    file.upload( urlReq );//This line does not work. No handler is executed. No http request hit the server side.
                    trace("after file upload test");
                }
                catch( e:Error )
                {
                    trace( e );
                }
            }

            //Complete Handler
            private function uploadComplete( event:Event ):void
            {
                trace( "Upload successful." );
            }

            //IOError handler
            private function ioError( error:IOErrorEvent ):void
            {
                trace( "Upload failed: " + error.text );
            }

            //SecurityError handler
            private function securityError(error:SecurityErrorEvent):void{
                trace( "Security error:" + error.text );
            }

            //Other handler
            private function someError(error:ErrorEvent):void{
                trace("some error" + error.text);
            }

            //Progress handler
            private function onProgress(event:ProgressEvent):void{
                trace("progressHandler"); 
            }


            //This method is executed to invoke the URLLoader.load when the Tricky Button is pressed.
            protected function OnTrickyButtonPressed(event:MouseEvent):void{
                var urlReq:URLRequest = new URLRequest("http://200.60.99.31/");//This points to a non-existed server
                urlReq.method = URLRequestMethod.POST;

                urlReq.data = new ByteArray();
                var loader:URLLoader = new URLLoader();

                try{
                    loader.load(urlReq);//This line seems very important in iOS7. It decides whether the latter file.upload can work. 
                                        //But in iOS8, file.upload does not work even if this line is executed.
                    trace("after urlloader load");
                }catch(e:Error){
                    trace(e);
                }
            }


        ]]>

    </fx:Script>

    <s:Button x="200" y="200"  width="400" height="200" label="Upload" click="OnUploadButtonPressed(event)" />
    <s:Button x="200" y="500"  width="400" height="200" label="Tricky" click="OnTrickyButtonPressed(event)" />  
</s:View>

当空气模拟器运行,它工作正常,如预期,然后在文件成功上传到服务器。 但是当iOS设备上执行的(在我的情况下,iPad的),我解释早,没有处理有关文件上传执行,并没有http请求时点击服务器。所以我觉得这个问题可以是在客户端

When executed on Air Simulator, it works fine as expected, and the file is successfully uploaded to the server. But When executed on iOS devices(in my case, iPad), as I explain early, no handler about the file upload is executed, and no the http request event hit the server. So I think the problem may be in the client side.

在我试图解决这个问题,我发现了一些棘手的有关i​​OS7这个问题。即,如果你在调用File.upload方法之前调用URLLoader.load方法(即使URLLoader.load指向一个不存在的地址),则File.upload可以发挥预期的上iOS7。更具体地说,当方法的的 OnTrickyButton pressed 的以上方法之前执行的的 OnUploadButton pressed 的,文件.upload会成功的iOS7。但是,这只是发生在iOS7。在iOS8,File.upload始终拒绝工作,不管URLLoader.load是否之前执行的。

During my try to solve the problem, I found something tricky about this problem on iOS7. That is, if you invoke the URLLoader.load method (even if the URLLoader.load points to a non-existed address) before invoking the File.upload method, the File.upload will work as expected on iOS7. More specifically, when method OnTrickyButtonPressed above is executed before method OnUploadButtonPressed, File.upload will succeed on iOS7. But this only happens on iOS7. On iOS8, File.upload always refuses to work, regardless of whether the URLLoader.load is executed before.

我想在我的情况下,问题不是出在以下两个链接中描述的沙盒问题或Firefox会话的问题,因为甚至没有任何http请求命中服务器端。 似乎AIR SDK中的iOS只发送失败由于某种原因HTTP请求。​​

I think in my case the problem is not the Sandbox problem or Firefox session problem described in the two links below, because not even any http request hit the server side. It seems that the Air SDK for iOS just failed to send the http request for some reason.

的Flex 4的FileReference问题与Firefox

How做我做的Firefox和Safari的Flex文件上传的工作?

为了使我的问题更清楚,我在下面列出我的环境:

To make my problem more clear, I list my environment below:

DEVELOMENT环境:Windows7的(64位)/ MAC OS 10.9.4(测试 两个OS平台上。) IDE:Flash Builder的4.7 空气SDK:3.8 / 16.0.0(当我更新到最新航空SDK 16.0.0 ,问题依然存在。) 应用程序服务器:Tomcat7 +春 Develoment Environment: Windows7 (64bit) / Mac os 10.9.4 (Tested on two OS platforms.) IDE: Flash Builder 4.7 Air SDK: 3.8 / 16.0.0 (After I updated to the lastest Air SDK 16.0.0 , the problem still exists.) Application Server: Tomcat7 + Spring

最后,我想用URLLoader.load是不是在我的情况选择,因为我要上传在未来的大文件,不能与URLLoader.load处理一提的是上传文件。

Finally, I would like to mention that uploading file using URLLoader.load is not an option in my case because I want to upload large files in the future, which can not be handled with the URLLoader.load.

我一直在努力为这个好几天。所以,我真的AP preciate它,如果任何人有这个任何想法。 先谢谢了。

I have been struggling for this for days. So I really appreciate it if anyone has any idea about this. Thanks in advance.

推荐答案

最后,我发现,真正的问题不在于code我提供的,它是关于HTTP代理自动配置,而这个问题发生在iOS7和iOS8。我所描述的问题,并详细一种变通方法,在下面的链接。希望这将帮助一些你。

Finally I found that the real problem is not about the code I provided, it is about the http proxy Auto configuration, and this problem happened on iOS7 and iOS8. I described the problem and a workaround in detail in the following link. Hope this will help some of you.

https://forums.adobe.com/thread/1716036

 
精彩推荐
图片推荐