无法使用angularJS显示图像

时间:2016-05-28 11:06:55

标签: javascript angularjs spring-mvc

您好我还是新的angularjs和spring mvc,我的服务器工作正常当我自己测试它时我可以看到图像但在客户端它不能正常工作而且我&#39 ; m在我的控制台中出现此错误angular.js:3153 GET数据:image / JPEG; base64,{} net :: ERR_INVALID_URL  请帮助。

ProductController.java

@RequestMapping(value = "/getImg/{id}", method = RequestMethod.GET)
    @ResponseBody
    public void getImg(@PathVariable long id, HttpServletResponse response) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        response.setHeader("Content-Disposition", "inline; filename=productImg.png");
        Model model = modelRepo.findById(id);
        model.getUrlImg();
        FileInputStream in = new FileInputStream(model.getUrlImg());
        byte[] buffer = new byte[1024];
        int len;
        while ((len = in.read(buffer)) != -1) {
            response.getOutputStream().write(buffer, 0, len);
        }

        response.setContentType("image");

    }

myService.js

getImg : function(id)
                        {
                            return $http
                            .get(
                                    'http://127.0.0.1:9001/PrototypePos/rest/products/getImg/'+id,
                                    {responseType : 'arraybuffer'})
                            .then(
                                    function(response) {
                                        return response.data;
                                    },
                                    function(errResponse) {
                                        console
                                                .error('Error while fetching clients');
                                        return $q.reject(errResponse);
                                    });
                        },

myController.js

$scope.getImg = function(id,$compileProvider) {
    ProductService.getImg(id).then(function(data) {
        $scope.image=data;
console.log($scope.image +"***************");



    }, function(errResponse) {
        console.error('Error while fetching allPdts');
    });
};

在我的HTML代码中:

<img ng-src="data:image/JPEG;base64,{{image}}">

0 个答案:

没有答案