1

Controller:

public async Task<ActionResult> LoadProductImage( long id, short width, short height )
        {                
                var byteArray = await _streamAceVqbzService.Proxy.DocumentByteArray_GetDataBy_IdAsync( id, width, height );

                return File( byteArray , "image/jpeg" );
            }    

Angular JS:

  getProductImage: function (imageId, width, height)
         {
             var deferred = $q.defer();
               $http.post('/Product/LoadProductImage', JSON.stringify({id:imageId,width:width,height:height})).success(deferred.resolve).error(deferred.reject);
                       return deferred.promise;
         }

     // Get product image. 
        $scope.loadProductImage = function (itemAttributes) 
         {
            var imageId = 0;
            $.each(itemAttributes, function (index, data)
            {
                if (data.AttributeId == 1000700 && data.DataXml != null)
                {
                    imageId = data.DataXml;
                    return false;
                }
            });
            productRepository.getProductImage(imageId, 200, 144).then(function (imageArrary) 
            {
                $scope.productImage = imageArrary;
            });
            return $scope.productImage = imageArrary;
        }

View:

<img class="ui-corner-all img-responsive defaultImageSize" ng-src="data:image/jpeg;base64;{{loadProductImage(product.ItemAttributes)}}" />
Ajay Sharma
  • 2,881
  • 5
  • 22
  • 32
  • We have tried it but it didn't works in our case. – Ajay Sharma Dec 10 '15 at 11:34
  • 1
    Instead of returning a `FileResult`, you need to return the image's base64 encoded string: `return Convert.ToBase64String(byteArray);` – IronGeek Dec 10 '15 at 11:39
  • @IronGeek Thanks , its worked for me. – Ajay Sharma Dec 11 '15 at 04:44
  • @IronGeek : It works but cause : “10 $digest iterations reached” – Ajay Sharma Dec 11 '15 at 06:00
  • @AjaySharma I'm not too familiar with angularjs, but from what I gather *“10 $digest iterations reached”* happens because the bindings keep getting reevaluated on every digest cycle. Perhaps the following question could provide some insight: http://stackoverflow.com/questions/28332674/calling-function-inside-angularjs-goes-in-endless-loop – IronGeek Dec 11 '15 at 08:22

0 Answers0