» Are you looking for FLV Player?

No custom headers for FileReference.upload. Why?

19 March 2008 | filed under actionscript, air, flash | 10 comments

ActionScript iconI got excited when I learned that YouTube opened their API for third party developers. This would enable me to - for example - create a nifty AIR widget to quickly upload videos to my YouTube account. Drag-and-drop a video file onto the AIR app and have the uploading done in the background. Cool!

So I took off, did the authentication stuff with the ClientLogin API so I was able to login into my YouTube account with Flash.

Next: add uploading functionality. Again, the docs are clear and I’m halfway done when I re-read the URLRequest.requestHeaders documentation, only to find out that custom headers (required for the YouTube upload to succeed) are not supported by FileReference.upload!

So much for my YouTube upload AIR widget…

Adobe, PLEASE consider removing this restriction from a future Flash player. Or please tell me why this restriction is imposed on the upload method, as I fail to see why we shouldn’t be allowed to create our own POST request headers for the upload method.

 

10 Responses to “No custom headers for FileReference.upload. Why?”

  1. Dave Nicoll says:

    Isn’t this the kind of thing you need..?

    var request:URLRequest = new URLRequest(_uploadUrl + “?filename=” + id);
    request.method = URLRequestMethod.POST;
    _f.upload(request, “image”, false);

  2. Martijn de Visser says:

    @Dave: Thanks for your feedback, but unfortunately, that doesn’t do the trick, as you really need control over the actual HTTP headers when the request is sent.

    So, adding variables and all woks fine, it is the requestHeaders where things break.

    It is ironic, actual uploading to YouTube works (yeehah!), but the file is rejected afterwards, beause the YT server cannot find the correct data it is ecpecting in the request headers. Sigh…

  3. Sidney de Koning says:

    What if you work with an proxy php file that, only when you upload you do a call to that file, php sends the custom header, and passes the result back to flash. I know you probably want to do this all in Flash without the need of any other languages, but it could solve your problems :)

    Cheers,

    Sid

  4. Sidney de Koning says:

    Maybee you this is your answer: http://framework.zend.com/download/gdata

    Good luck and keep us posted on any developemnts!

    Sid

  5. Martijn de Visser says:

    @Sidney - yeah a proxy could certainly do the trick, but I wanted to create a standalone app. I’ll have a look and see if using a proxy means that the actual upload will go ‘through’ the proxy. If not, this could be a solution, else my server would soon die if many people start using such an app (due to bandwidth limitations).

  6. isxylands says:

    @Dave:
    I think Martijn need this:
    var request:URLRequest = new URLRequest(_uploadUrl + “?filename=†+ id);
    request.method = URLRequestMethod.POST;
    request.setHeader(”headerName”, “headerValue”);
    // or request.addHeader(”headerName”, “appendedValue”);
    _f.upload(request, “imageâ€, false);

    but adobe not support this yet…

  7. Martijn de Visser says:

    @isxylands - yes, that is sort of what you need, but like I said, request headers are simply ignored by the Flash Player when they are added to a FileReference.upload request. Bummer.

  8. Stan says:

    seems to be a similar issue as the filereference issue for mac users. I’m not sure if there’s a link, but I hope Adobe starts urgent with improving the filereference possibility. That would be necessary to be able to build professional cross platform web applications.

  9. Sidney de Koning says:

    Hi Martijn,

    Did some research on this; Why not use the Socket Class? That way you can read/write anything to a specific port. And also write the custom header needed for this google api auth. Try looking into that.

    Hope this helps,

    Sidney de Koning

  10. Martijn de Visser says:

    Hm, intersting - not sure if I can make a regular POST requist using Sockets though. Thanks for your feedback!

Leave a Reply