3
votes

I am using Ruby, RestfulX, and Paperclip to upload a File, using the FileReference class.

I get the response from Paperclip in the terminal that says I've successfully saved the file, but it appears Flash never gets what it needs to know the upload has been successful.

I'm getting this error if I try to upload again while the CursorManager's clock is spinning:

Error: Error #2174: Only one download, upload, load or save operation can be active at a time on each FileReference.

It seems that I need to tell Flex that I've successfully saved the file. Is there a way to manually do that? Do I need to pass a session or cookie or anything?

3

3 Answers

2
votes

In my web services (PHP/Python) I send a response via the service. The upload occurs, is processed and a return is sent that Flex/FLash event handler uses as a response. If there is no return on the service side, Flex/Flash will not know that anything as happened, and as such the event handler will not be activated. Generally this can be as simple as a return True statement, or something more complex depending on your needs.

So FileReference generally dispatches an Event.COMPLETE when it is finished. I am guessing that this is what handles the mechanisms internally. I wonder if the DataEvent is somehow going around that mechanism? You could manually dispatch the Event.COMPLETE from the FileReference in your handler.

fileReference.dispatchEvent(new Event(Event.COMPLETE));

not the prettiest of solutions, but I'd be curious if it worked.

0
votes

The better solution is to call: fileReference.cancel();

I have also found that with uploads to try again (eg. in case of a network problem), it's better to re-reference the file:

var url : String = fileReference.url;
fileReference.cancel();
fileReference = new File(url);

and you can do again: fileReference.upload()

0
votes

You should call fileReference.cancel() before calling browse method. This resets the fileReference before every browse call.

fileReference.cancel();
fileReference.browse( [new FileFilter( "Excel", "*.xls;*.xlsx" )] );