首页 > 解决方案 > 图像未显示在图像视图中,而在邮递员中它运行良好

问题描述

我真的很困惑在ImageView. 实际上,当我URL在邮递员中点击我的 URL 时,我得到了一个文件和另一件事,它运行良好。当我尝试使用Glide和其他类似的东西时,Picasso我没有从服务器获取图像。

请建议我可以为它做些什么。

我在 java 中的服务器代码在这里你也可以检查它。

    @RequestMapping(value = "downloadBlog", method = RequestMethod.GET)
public ResponseEntity<?> downloadBlogImage(@RequestParam(value = "id", required = false) Long id) {

    StayHealthyBlog dbFile = checkUserService.findBlogById(id);
    return ResponseEntity.ok().contentType(MediaType.parseMediaType(dbFile.getImageType()))
            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"xyz" + "\"")
            .body(new ByteArrayResource(dbFile.getImageData()));
}

现在我怎么能得到我的形象..

提前致谢。

标签: javaandroidspring

解决方案


替换这一行:

@RequestMapping(value = "downloadBlog", method = RequestMethod.GET)

和:

@RequestMapping(value = "downloadBlog", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)

更新

确保 URLhttp://forGlidePicasso识别链接协议开头。

    Picasso.get().load("http://" + url).into(imageView); // If server return url without `http{s}://`

推荐阅读