yeah, i missed step to making blob out of base64 image file.
now its working. here is sample code.
// boilerplate function to create a Blob
$scope.dataURItoBlob = function(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for (var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
return new Blob([new Uint8Array(array)], {
type: mimeString
});
}
$scope.upload = function(imageURI) {
// Configure The S3 Object
AWS.config.update({
accessKeyId: $scope.creds.access_key,
secretAccessKey: $scope.creds.secret_key
});
/*AWS.config.region = 'us-east-1';*/
var bucket = new AWS.S3({ params: { Bucket: $scope.creds.bucket } });
if(imageURI) {
var data = $scope.dataURItoBlob(imageURI);
var params = {
Key: $scope.guid + '/' + 'profileImg.jpg',
ContentType: 'image/jpeg',
Body: data,
ACL: "public-read",
};
bucket.putObject(params, function(err, data) {
if(err) {
// There Was An Error With Your S3 Config
//console.log("THIS ERROR:", err);
return false;
}
else {
// Success!
$scope.data.profileImg = imageURI;
$scope.$digest();
window.localStorage.profileImg = $scope.data.profileImg;
/*alert('Upload Done');*/
}
})
.on('httpUploadProgress',function(progress) {
// Log Progress Information
//console.log(Math.round(progress.loaded / progress.total * 100) + '% done');
});
}
else {
// No File Selected
//alert('No File Selected');
}
}