Skip to main content
Participating Frequently
August 24, 2010
Question

Flash interprets 3xx redirect responses as errors.

  • August 24, 2010
  • 1 reply
  • 2891 views

Hi I am trying to upload videos to the YouTube API, it used to work great, butsomething has changed and now Flash interprets 3xx redirect responses as errors!

I found a post on another forum where somebody has commented on the issue much better than i can, but there is still no answer

Help please? I think this is an actual BUG in flash though...

[ANOTHER GUYS QUESTION]

Please help us to solve the following issue:

We are uploading a video to YouTube using the FileReference.upload()
method in AS3/Flex.  When it finishes, YouTube sends a status 302,
which causes FileReference to trigger an IOErrorEvent. ResponseURL
parameter is empty with no any data to extract. Of course, we expect
here status 200 and after some tests we noticed the problem is
connected with versions of Flash Player.

We tested on next versions and:
10.0.42.34 worked (received status 200)
10.0.42.45 didn't work (received status 302)
10.1.53.64 didn't work (received status 302)

Also we found some older post from July 7, 2009 on
http://blog.curiousmedia.com/?q=blog/upload-youtube-flash which
describes the same problem in section "The Mac problem" but with no
correct solution.

Something similar about status 302 was said and for Youtube API for
Python where the one should set ssl param to False to receive correct
status back, but we are not sure how this can be implemented in
context of flash. Here is the post about it:
http://stackoverflow.com/questions/2863785/gdata-youtube-api-302-the-...

We tried to search alot all over the internet and Youtube's Docs, but
there is no any mention about the solution for this problem.

Thanks for any reply in advance!

[YOUTUBES ANSWER]

Hi there,

I ran the example you are referring to and I'm getting 302, as expected
since it is basically utilizing the browser-based uploading mechanism which
triggers a redirect.
From AS3 documentation I gather that, ioError event always follows
httpStatus event :

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/n...

and this is what I see while running the uploader in Flex 10.x plugin :

[HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false
eventPhase=2 status=302 responseURL=null]
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2
text="Error #2038: File I/O Error. URL:
http://uploads.gdata.youtube.com/action/FormDataUpload/AIwbFARxu-IiTy...
"]

The file does get uploaded to YouTube, as expected. However, it looks like
Flash interprets 3xx redirect responses as errors.

The challenge of coming up with a better solution is related to limitations
of flash.net.FileReference, currently it does not allow one to set custom
request headers in Flash (from docs I gather that it is possible in Adobe
Air though) to implement, for example, resumable uploads.

Thanks,

Jarek Wilkiewicz, YouTube API Team

Any ideas gurus????

Cheers

    This topic has been closed for replies.

    1 reply

    Participant
    October 18, 2012

    HI, i'm currently facing tha same issue, succesfull uploads but a non usable response object from event:

    [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=302 responseURL=null]

    Did u ever solved it or found a solution for this?

    this is my actual code:

    package com.theguaz {

       

        import flash.display.*;

        import flash.events.*;

        import flash.net.*;

        import flash.system.*;

        import flash.external.ExternalInterface;

       

        import com.adobe.serialization.json.*

       

        import com.greensock.TweenMax;

        import com.greensock.easing.*

        import com.greensock.plugins.*;

        public class FinalConnector extends MovieClip {

           

            private const _getTokenURL:String = "http://clientloginsolverUrl/youtube.php";

            private var _fileReference:FileReference;

            private var _uploadComplete:Boolean;

            private var _postUrl:String;

            private var _nextUrl:String;

            private var _token:String

           

           

            public function FinalConnector() {

                // constructor code

                addEventListener(Event.ADDED_TO_STAGE, configUI);

            }

           

            private function configUI(e:Event):void {

                stage.scaleMode = StageScaleMode.NO_SCALE;

                stage.align = StageAlign.TOP_LEFT;

                setupBtns();

            }

           

            private function setupBtns():void{

                login_btn.addEventListener(MouseEvent.CLICK, clickEventHandler);

                upload_btn.addEventListener(MouseEvent.CLICK, clickEventHandler);

                upload_btn.alpha = .1; upload_btn.mouseEnabled = false;

            }

           

            private function clickEventHandler(e:MouseEvent):void{

                switch(e.currentTarget){

                    case login_btn:

                        youTubeLoginGateway();

                    break;

                    case upload_btn:

                        doUploadClick();

                    break;

                    /*case logout_btn:

                        doLogoutClick();

                    break;*/

                }

            }

           

            private function youTubeLoginGateway ():void {

                var urlRequest:URLRequest = new URLRequest(_getTokenURL);

                urlRequest.method = URLRequestMethod.GET;

                var urlLoader:URLLoader = new URLLoader();

                urlLoader.addEventListener(Event.COMPLETE, authCompleteHandler);

                urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, authFailedHandler);

                urlLoader.addEventListener(IOErrorEvent.IO_ERROR, authFailedHandler);

                urlLoader.load(urlRequest);

            }

           

            private function authCompleteHandler(event:Event):void {

                var urlLoader:URLLoader = URLLoader(event.target);

                var result:Object = JSON.decode(urlLoader.data);

                _token = result.token;

                _postUrl = result.postUrl;           

                upload_btn.alpha = 1; upload_btn.mouseEnabled = true;

                label_txt.text = urlLoader.data;

            }

           

            private function authFailedHandler(event:ErrorEvent):void {

                var loginErrorEvent = event;

                ExternalInterface.call("console.log", loginErrorEvent);

            }

           

            private function doUploadClick():void {

              _fileReference = new FileReference();

              _fileReference.addEventListener(Event.SELECT, fileSelectHandler);

              _fileReference.addEventListener(ProgressEvent.PROGRESS, progressHandler);

              _fileReference.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

              _fileReference.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

                  var videoFilter:FileFilter = new FileFilter("Video", ".*f4v; *.flv; *.wmv; *.mpeg; *.mpg; *.f4v; *.vp8; *.webm; *.3gp; *.mp4; *.mov; *.avi; *.mpegs; *.mpg; *.3gpp;");

                _fileReference.browse([videoFilter]);

            }

            private function httpStatusHandler(event:HTTPStatusEvent):void {

              // Browser-based uploads end with a HTTP 302 redirect to the 'nexturl' page.

              // However, Flash doesn't properly handle this redirect. So we just use the presence of the 302

              // redirect to assume success. It's not ideal. More info on browser-based uploads can be found at

              // http://code.google.com/apis/youtube/2.0/developers_guide_protocol_browser_based_uploading.html

               

                  if (event.status == 302) {

                    trace(event);

                    _uploadComplete = true;

                    label_txt.text = 'File uploaded successfully.';

                    TweenMax.to(label_txt, .25, {alpha:1});

                   

                   

                  }

            }

            private function fileSelectHandler(event:Event):void {

                _fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);

                uploadFile();

            }

           

            private function uploadCompleteHandler(event:Event):void {

                label_txt.text = "File Uploaded: " + event.target.name;

            }

           

            private function progressHandler(event:ProgressEvent):void {

                  var percent:Number = Math.round(100 * event.bytesLoaded / event.bytesTotal);

                label_txt.text = String(percent);

            }

           

            private function ioErrorHandler(event:IOErrorEvent):void {

                  // uploadComplete is set in the httpStatusHandler when the HTTP 302 is returned by the YouTube API.

                  if (!_uploadComplete) {

                    trace('An error occurred: ' + event);

                  }

            }

           

            private function uploadFile():void {

                var variables:URLVariables = new URLVariables();

                variables.token = _token;

                variables.nextUrl = "http://whatsoever/success.php";

                label_txt.text = "uploading...";

                TweenMax.to(label_txt, .25, {yoyo:true, repeat:-1, alpha:.5});

                var fileUploadUrl:URLRequest = new URLRequest(_postUrl);

                fileUploadUrl.contentType = "multipart/form-data";

                fileUploadUrl.method = URLRequestMethod.POST;

                fileUploadUrl.data = variables

               

                  _fileReference.upload(fileUploadUrl, 'file');

            }

           

           

           

            //////////// END OF CLASS

        }

    }

    regards

    chris.campbell
    Legend
    October 18, 2012

    If this is a change of behavior with the recent versions of Flash Player I'd like to suggest opening a bug on this at http://bugbase.adobe.com.  Once added, please post back with the bug URL and I'll have someone investigate.

    Thanks,

    Chris

    Participant
    October 18, 2012

    Thank's Chris, here is the link to the BUG: https://bugbase.adobe.com/index.cfm?event=bug&id=3349386

    Hope you can take a look on it.

    regards.