如何将图像从服务器发送到客户端?

javaNoob

我一直在学习春天,为了使事情变得更紧密,我正在制作一个电子商务应用程序。我已使用rest api连接客户端和服务器。现在,我需要将图像发送到客户端。我的图像已经存储在src / resources文件夹中。我需要知道的是如何通过Rest API发送这些图像。这样我就可以在客户中使用它

我对此很不高兴。我尝试了谷歌,我所能找到的就是将图像文件上传到服务器的示例。我找不到通过rest api从服务器向客户端发送文件的示例。我已经被困在这三天了

这是我的休息控制器:现在我需要知道下一步该怎么做才能发送图像

@RestController
@RequestMapping("/api")
public class CategoriesRestController {

// autowire customer service
@Autowired
private CategoriesService service;


//add mapping for GET all customer
@GetMapping("/categories")
public List<Categories> getCategories() {

    return service.getCategories();
}

// adding mapping for GET only one customer
@GetMapping("/categories/{categoryId}")
public Categories getCategory(@PathVariable int categoryId) {

    Categories categories = service.getCategory(categoryId);

    if(categories == null) {
        throw new CustomerNotFoundException("Customer id not found- "+ categoryId);
    }else {
    return categories;
    }
}

// adding mapping for POST/customer i.e. insert a customer
@PostMapping("/categories")
public Categories addCategories(@RequestBody Categories theCategories) { //@RequestBody will convert JSON to JAVA object

    // just to make things clear... always set id to 0 when inserting new object
    // so that it will be created instead of update
    theCategories.setId(0);
    service.saveCategories(theCategories);

    return theCategories;
}
姆布里奇

您可能会以错误的方式思考问题。HTML不需要通过其余的API发送图像本身,而是仅需要图像的路径。您将图像存储在目录中,并且可以将图像的路径传递到HTML。您可以将变量“ imagePath”添加到“类别”,HTML可以在标记中引用它

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将空的终端输出从服务器发送到客户端?

如何将Spring Boot管理客户端元数据发送到管理服务器

如何将消息从golang的websocket服务器主动发送到客户端

如何将Android客户端注册令牌发送到FCM服务器?

将图像从Java客户端发送到python服务器

Angular2:发出请求时如何将数据从客户端发送到服务器

如何将信息从NodeJS服务器发送到客户端?

如何将通知从node.js服务器发送到android客户端。

如何将数据从客户端的html发送到node.js服务器?

如何将客户端数据发送到服务器端

通过套接字连接将图像从客户端发送到服务器

使用REST API将图像从服务器发送到客户端

如何将数据(字符串)从HTTP客户端发送到服务器

如何将JPG文件从服务器发送到客户端

如何将多个数据流从单个客户端发送到TCP服务器

如何通过获取将更新的变量从客户端发送到服务器?

如何将信息从客户端发送到服务器(Flask-python)

如何使用C ++中的Websocket客户端将消息发送到服务器?

Ruby如何通过TCP(http)服务器将图像发送到客户端

如何将数据从UDP服务器发送到NAT后的UDP客户端?

如何将邮件从服务器发送到特定客户端

服务器如何使用Java将消息发送到客户端

如何将参数从CometD客户端发送到CometD服务器

如何将图像(UIImage)从 SWIFT ios 客户端程序发送到 JAVA 服务器程序?

在python中使用HTTP将图像从服务器发送到客户端

React 和 NodeJS:如何将数据从服务器发送到客户端?

如何将表单数据从客户端发送到服务器

如何将值从 golang 发送到 vue js(服务器到客户端)?

如何将数据发送到多线程服务器上的特定客户端