gpt4 book ai didi

java - 如何在react中从服务器获取文件

转载 作者:行者123 更新时间:2023-12-02 08:48:21 24 4
gpt4 key购买 nike

我的 Controller 中有方法:

    @GetMapping("/photos")
public ResponseEntity<?> getPhotos(){
List<Photo> photoList = photoService.findAll();
return new ResponseEntity<>(photoList, HttpStatus.OK);
}

它从数据库返回数组:[{"id": 1,"name": "photo1.jpg","file": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wC...(byte[])"},{...},. ..]我知道一个文件是这样完成的:

.then(response => {
response.blob().then(blob => {
let url= window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
});
});

但是如何处理数组呢?

最佳答案

您可以使用response.json()代替。

.then(response => {
response.json().then(responseJSON => {
// responseJson should be an array that you can iterate on and manipulate individual objects and parse relevant keys.
});
});

关于java - 如何在react中从服务器获取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60939801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com