PostgreSQL - 如何将 Base64 图像字符串插入 BYTEA 列? [英] PostgreSQL - How to insert Base64 images strings into a BYTEA column?

查看:11
本文介绍了PostgreSQL - 如何将 Base64 图像字符串插入 BYTEA 列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 SQL:

CREATE TABLE Documents (
  Id INT NOT NULL,
  UserId INT NOT NULL,
  Label CHARACTER VARYING(220) NOT NULL,
  Image BYTEA NOT NULL,
  PRIMARY Key(Id),
  FOREIGN KEY (UserId) REFERENCES Users(Id)
);

我想知道,我应该如何将Base64图像插入表格中.

I want to know, How should I have to insert the Base64 image into the table.

Base64 字符串来自使用 fs Node.js 上的模块.

The Base64 string comes from a Buffer from after getting the image using the fs module on Node.js.

我正在尝试使用 Sequelize 的原始查询插入图像,但我没有找到关于此的适当信息.

I'm attempting to insert the image using raw queries of Sequelize, but I have not found proper information on this.

推荐答案

试试这个:

insert into table_name (image)
values decode('AcAAFBAO5Az....AQAAAFBCO5gT/AEAABT', 'base64')

这里有一些关于decode

https://www.base64decode.net/postgresql-decode

这篇关于PostgreSQL - 如何将 Base64 图像字符串插入 BYTEA 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆