【发布时间】:2019-08-25 03:48:42
【问题描述】:
我正在尝试在 postgres 数据库中保存一些图像,但只保存了 10 个字节的数据。
流程是这样的:
我在我的服务器上收到一个 base64 编码的字符串,然后我将它加载到一个缓冲区,将它设置到我的实体并保存它。 但随后尝试从 db 中恢复该信息,我只得到 10 个字节的数据,在查询中使用 octet_length() 进行验证。
我的实体属性定义:
@Column({ "name": "entima_imagem", "type": "bytea", "nullable": false })
entima_imagem: Buffer;
我接收数据并保存的代码:
entity.entima_imagem = Buffer.from(base64String, "base64");
const repository = this.getRepositoryTarget(Entity);
const saved = await repository.save<any>(entity);
在服务器上,在保存之前,我正在将文件写入磁盘,我可以毫无问题地对其进行可视化。
【问题讨论】:
标签: node.js postgresql typescript nestjs typeorm