2

I am trying to get an application to upload multiple client side generated images (not files, hence I can't use FileReference), while displaying the progress of the upload. This has proved to be way harder than it should be. I am using Cairngorm Task library to perform the following steps on an image generated on the client:

  1. Generate a BitmapData object drawing the contents of an area of the stage
  2. Encode the image as a JPEG asynchronously, as to show a progress bar (see http://dgrigg.com/blog/2009/03/05/as3-jpegencoder-and-big-images/)
  3. Upload the image asynchronously (chunked, see http://soenkerohde.com/2010/01/chunk-file-upload/) to show progress

When the user clicks a button, the SequenceTask gets started, the encoding works like a charm, but when the uploading task occurs, it bursts into flames with the error:

SecurityError: Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.

I believe this is occurring because you cannot initiate a URLLoader.load action without user intervention. Even though the user is clicking on the button, I think because things start happening asynchronously this click event is no longer being considered as the originator.

Is there a way to let URLLoader know that this is the result of the mouse click? This will be indispensable for the chunked upload to work, because all of the subsequent chunks will initiate a new URLLoader as well, so I'm not 100% sure the chunked uploader from the reference actually works. I might try running just their plain code first.

Thanks for any ideas.

Ruy Diaz
  • 3,084
  • 24
  • 36

3 Answers3

1

You have to change your application flow in order to force a user interaction before the upload.

This behaviour was introduced on Flash Player 10 (I'm almost sure this didn't happen with URLLoaders on Flash Player 9) and there's no way to circumvent it, otherwise it would be a major security hole. Dispatching "fake" mouse events will not work, the upload/POST has to be done on the same callstack where the user interaction (mouse click or keyboard shortcut) is captured.

Check "User interaction requirements in Flash Player 10" for more information.

bmleite
  • 26,850
  • 4
  • 71
  • 46
  • So there is no way to show upload progress for multiple file upload then? Or defer the uploading until after the asynchronous encoding? Would I have to do the encoding and then ask the user to click "Upload" for the upload to begin? – Ruy Diaz Mar 24 '11 at 17:04
  • Apparently this only happens if the URLLoader POST contains a 'filename' attribute in the Content-Disposition header. I seem to be able to get around my problem by Base64 encoding my file and sending it as a string in a post variable. Right now I seem to be having trouble reassembling the image on the server side, but it seems to be a Ruby problem at this point. Will post results. – Ruy Diaz Mar 24 '11 at 18:36
  • Base64 encoding worked. I am able to send multiple POST requests. It adds a little bit of overhead in terms of processing and data transmitted, but it solves the problem of showing a progress bar for uploading through URLLoader. – Ruy Diaz Mar 24 '11 at 20:09
0

I am now with the same problem than yours one. I have several images and only the first upload work like a charm but in the second upload, it's stopped arising the following error: "SecurityError: Error #2176", and watching your post i realized that it's due to an internal call the second upload instead of a user interaction.

I have tried with many options, one of then were closing the URLloader with close() before starting the next upload and the same error. The trick is emulating a user interaction.

domoindal
  • 1,513
  • 2
  • 17
  • 33
0

Could you mimic the user action by dispatching a MouseEvent object?

I've tried doing a FileReference.save() on my end just by calling it (it's not meant to work without an user interaction), but it works, so maybe there's something different with my configuration

divillysausages
  • 7,883
  • 3
  • 25
  • 39