Last active
December 19, 2015 15:29
-
-
Save dmitryevseev/5977045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fd = new FormData(), | |
image = <data_to_post>; | |
fd.append('file', image);//upload file urlData | |
var xhr = new XMLHttpRequest(); | |
//register upload progress event listener | |
xhr.upload.addEventListener("progress", function (event) { | |
//uploadProgress(event, fileIndex); | |
}, false); | |
xhr.addEventListener("load", function (event) { | |
//uploadComplete(event, fileIndex); | |
}, false); | |
xhr.addEventListener("error", function (event) { | |
//uploadError(event, fileIndex); | |
}, false); | |
xhr.addEventListener("abort", function (event) { | |
//uploadAbort(event, fileIndex); | |
}, false); | |
xhr.onload = function (event) { | |
if (this.status == 200) { | |
//image successfully uploaded - populate object with received data | |
var apiResponse = JSON.parse(this.responseText); | |
$scope.$apply(function () { | |
// read backend response from apiResponse | |
}); | |
} else { | |
//some error occurred | |
apiResponse = JSON.parse(this.responseText); | |
if (apiResponse.callStatus.status === 'failure') { | |
$scope.$apply(function () { | |
// read backend response from apiResponse | |
}); | |
} | |
} | |
}; | |
//send file to server | |
xhr.open("POST", '/uploadImage'); | |
xhr.send(fd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment