Can anyone please help on this.
I need to upload file into PostgreSQL database using TypeORM/NestJS. file is part of a form.
I have taken below entity class.
export class Certificate {
@ApiProperty()
@PrimaryGeneratedColumn()
@Exclude()
id: number;
@ApiProperty()
@Column({ type: 'varchar', length: 15 })
statusOfReport: string;
@ApiProperty()
@Column({ type: 'varchar', length: 100 })
sponser: string;
@ApiProperty()
@Column({ type: 'varchar', length: 100 })
address: string;
@ApiProperty()
@Column({ type: 'varchar', length: 100 })
address2: string;
@ApiProperty()
@Column()
zipCOde: string;
@ApiProperty()
@Column()
city: string;
@ApiProperty()
@Column()
protoColNo: string;
@ApiProperty()
@Column()
molecules: string;
@ApiProperty()
@Column()
unAuthMolecule: string;
@ApiProperty()
@Column()
phaseOfTrial: number;
@ApiProperty()
@Column()
noOfSubjects: number;
@ApiProperty()
@Column()
startDate: Date;
@ApiProperty()
@Column()
endDate: Date;
@ApiProperty()
@Column()
personInCharge: string;
@ApiProperty()
@Column()
country: string;
@ApiProperty()
@Column()
comments: string;
@ApiProperty()
@Column({ type: 'bytea' })
attachFile: Uint8Array;
Below is my controller method.
@Post()
create(@Body() createCertificateDto: CreateCertificateDto): Promise<Certificate> {
return this.certificatesService.create(createCertificateDto);
}
below is my service class method.
async create(createCertificateDto: CreateCertificateDto): Promise<Certificate> {
return this.certificateRepository.save(createCertificateDto);
}
I am saving file as data. what changes I need to do to upload file in database. file can be excel, pdf, text etc. Existing answers are not helping.

pg_read_filereturnstext, notbyteayou need to usepg_read_binary_file- but that will only work if Postgres is also running on the computer where you run pgAdmin