I want to fetch images from s3 and display them on my HTML page.
Angular HTML file:
<section data-ng-controller="myCtrl">
<img ng-src="{{src}}" width="200px" height="200px">
</section>
Angular Controller file:
angular.module('users').controller('myCtrl', ['$scope',function($scope) {
var s3 = new AWS.S3();
s3.getObject({Bucket: 'mybucket', Key: 'myimage.jpg'},function(err,file){
//code?? to display this image file in the img tag
//$scope.src=file????....obviously it wont work
});
}]);
I found something call FileReader and tried this one:
var reader = new FileReader();
reader.onload = function(event) {
$scope.src = event.target.result;
}
reader.readAsDataURL(file);
But it shows error:
Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
Please help me with the code to display image file in the img tag
My S3 bucket is not public
EDIT:
I am not interested in s3. what i want to know is that
how to display an image which you have in your javascript code in the form of a file object(s3 obj) using the HTML image tag