Skip to content

Commit

Permalink
Merge pull request #67 from im-saxo/master
Browse files Browse the repository at this point in the history
flash upload error http status
  • Loading branch information
RubaXa committed Feb 12, 2013
2 parents 562dc54 + 6e16ca6 commit 8254f97
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
Binary file modified FileAPI.flash.swf
Binary file not shown.
6 changes: 4 additions & 2 deletions flash/src/ru/mail/commands/UploadFileCommand.as
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package ru.mail.commands
public class UploadFileCommand extends AbstractUploadFileCommand
{
private var fileRef:FileReference;
private var status:String = null; // httpStatus. in case of upload error we get httpStatus event followed by ioError event. add status to error event using this temp variable

public function UploadFileCommand(fileRef:FileReference, url:String, headers:Object, uploadPostData:Object, uploadDataFieldName:String)
{
Expand Down Expand Up @@ -103,7 +104,8 @@ package ru.mail.commands
private function onHTTPStatus(event:HTTPStatusEvent):void
{
trace ("onHTTPStatus", event);
LoggerJS.log("fileReference.upload HTTPStatusEvent: " +event.status)
LoggerJS.log("fileReference.upload HTTPStatusEvent: " +event.status);
status = event.status.toString();
dispatchEvent(new TextEvent("httpStatus", false, false, event.status.toString() ) );
}

Expand All @@ -120,7 +122,7 @@ package ru.mail.commands
LoggerJS.log("fileReference.upload onError: " +event.toString());

trace ("onError", event);
complete(false, null, new ErrorVO(event.toString(), errorType) );
complete(false, null, new ErrorVO(event.toString(), errorType, status) );
}

private function onProgress(event:ProgressEvent):void
Expand Down
6 changes: 4 additions & 2 deletions flash/src/ru/mail/commands/UploadImageCommand.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package ru.mail.commands
private var _files:Object;
private var _totalSize:int = 0;
private var _loader:MultipartURLLoader;
private var status:String = null; // httpStatus. in case of upload error we get httpStatus event followed by ioError event. add status to error event using this temp variable

public function UploadImageCommand(files:Object, url:String, headers:Object, uploadPostData:Object)
{
Expand Down Expand Up @@ -130,7 +131,8 @@ package ru.mail.commands
private function onHTTPStatus(event:HTTPStatusEvent):void
{
trace ("onHTTPStatus", event);
LoggerJS.log("urlloader.upload onHTTPStatus: " +event.toString());
LoggerJS.log("urlloader.upload onHTTPStatus: " +event.status);
status = event.status.toString();
dispatchEvent(new TextEvent("httpStatus", false, false, event.status.toString() ) );
}

Expand All @@ -147,7 +149,7 @@ package ru.mail.commands
LoggerJS.log("fileReference.upload onError: " +event.toString());

trace ("onError", event);
complete(false, null, new ErrorVO(event.toString(), errorType) );
complete(false, null, new ErrorVO(event.toString(), errorType, status) );
}

private function onProgress(event:ProgressEvent):void
Expand Down
2 changes: 1 addition & 1 deletion flash/src/ru/mail/controller/AppController.as
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ package ru.mail.controller
if (event.error.error.indexOf("#2038") > -1) {
_model.hasError = true;
}
_jsCaller.callJS( callback, {type:"error", message:event.error.getError() } );
_jsCaller.callJS( callback, {type:"error", message:event.error.getError(), status:event.error.httpStatus } );
}

uploadCommand.dispose();
Expand Down
6 changes: 5 additions & 1 deletion flash/src/ru/mail/data/vo/ErrorVO.as
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ package ru.mail.data.vo
public var errorType:String = "error";
public var errorID:String = "";
public var errorMessage:String = "";
public var httpStatus:String = '';

public function ErrorVO(error:String, errorType:String = null)
public function ErrorVO(error:String, errorType:String = null, httpStatus:String = null)
{
super();
parseError(error);
if (errorType) {
this.errorType = errorType;
}
if (httpStatus) {
this.httpStatus = httpStatus;
}
}

public function parseError(str:String):void {
Expand Down
4 changes: 2 additions & 2 deletions lib/FileAPI.Flash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* FileAPI fallback to Flash
*
* @flash-developer "Vladimer Demidov" <[email protected]>
* @flash-developer "Vladimir Demidov" <[email protected]>
*/
(function (api, window, document){
api.support.flash = (function (){
Expand Down Expand Up @@ -463,7 +463,7 @@
_this.end(evt.status || 200);
}
else if( type == 'abort' || type == 'error' ){
_this.end(0, evt.message);
_this.end(evt.status || 0, evt.message);
_unwrap(upload);
}
})
Expand Down

0 comments on commit 8254f97

Please sign in to comment.