spring-boot - 在 Flutter 应用程序中消耗 Spring Boot 资源?(响应对象字节数组到文件)
问题描述
我有一个 Spring Boot 后端,它为我提供文件(在本例中为 jpeg 文件)。
这是弹簧休息控制器的样子:
@Override
public ResponseEntity<Resource> get(Long id) {
MyCustomFile entity = service.get(id);
if (entity == null) {
return ResponseEntity.notFound().build();
}
return new ResponseEntity<>(toResource(entity), toHeaders(entity), HttpStatus.OK);
}
protected Resource toResource(MyCustomFile myfile) {
return toResource(myfile.getContent());
// here the getContent() returns array of bytes: private byte[] content;
}
protected Resource toResource(byte[] data) {
return new ByteArrayResource(data);
}
但是如何在我的颤振应用程序中使用它呢?目前我有这个:
getFileById(int id, String token) async {
var response = await http.get(Uri.parse("$URL$id"), headers: {
HttpHeaders.authorizationHeader: 'bearer $token',
});
}
我有这个response
对象,但我不知道如何变成一个文件以便我可以处理它......(例如将它保存到手机......)
当我打印response.body
:
解决方案
推荐阅读
- javascript - Nightwatch.js:点击文本链接
- android - 打开另一个应用程序的 Intent (getLaunchIntentForPackage()) 总是返回到第一个活动
- javascript - 我应该用打字稿将我所有的快递服务器包装在一个类中吗?
- javascript - 无法让 javascript 在我的网站上运行;Django 民意调查
- linux - MPI 无法编译基准(未定义对“MPI_Type_extent”的引用)
- php - Laravel - MethodNotAllowedHttpException。邮政
- excel - 如何在模型-视图-演示者模式中设计模型?
- javascript - jQuery nextUntil 与孩子
- c# - 登录只接受第一个用户
- spring - Spring中下拉列表中的空值