Postgresql JHipster Liquibase:如何上传图像文件blob?

Postgresql JHipster Liquibase:如何上传图像文件blob?,postgresql,jhipster,liquibase,Postgresql,Jhipster,Liquibase,给定一个包含以下列的表: <column name="image" type="longblob"> <constraints nullable="true" /> </column> <column name="image_content_type" type="varchar(255)"> <constraints nullable="true" /> </column> 如何从文件(例如MyIma

给定一个包含以下列的表:

<column name="image" type="longblob">
    <constraints nullable="true" />
</column>
<column name="image_content_type" type="varchar(255)">
    <constraints nullable="true" />
</column>


如何从文件(例如MyImage.jpeg)上载图像?底层数据库是PostgreSQL。

以下变更集实现了我所需要的功能:

    <changeSet id="632342634534534e53" author="developer">
    <update schemaName="public"
            tableName="my_table">
        <column name="image" type="longblob" valueBlobFile="../../../images/1.MyImage.jpg"/>
        <column name="image_content_type" type="varchar(255)" value="image/jpeg"/>
        <where>id = 1</where>
    </update>
    </changeSet>

以下变更集符合我的要求:

    <changeSet id="632342634534534e53" author="developer">
    <update schemaName="public"
            tableName="my_table">
        <column name="image" type="longblob" valueBlobFile="../../../images/1.MyImage.jpg"/>
        <column name="image_content_type" type="varchar(255)" value="image/jpeg"/>
        <where>id = 1</where>
    </update>
    </changeSet>

我也有类似的问题,但在我的例子中,只要列类型是OID而不是Blob(postgres 12.x),接受的解决方案就行不通

所以我最终得到了下面的解决方案,它使用computedValue和postgres函数将Base64图像转换为OID

 <insert tableName="IMAGES">
        <column name="image_id" valueSequenceNext="image_id_seq"/> 
        <column name="name" value="some image name"/>
        <column name="content" valueComputed="lo_from_bytea(0, decode('DLxmEfVUC9CAmjiNyVphWw==', 'base64'))"/>
    </insert>


希望它能帮助别人

我也有类似的问题,但在我的例子中,只要列类型是OID而不是Blob(postgres 12.x),接受的解决方案就行不通

所以我最终得到了下面的解决方案,它使用computedValue和postgres函数将Base64图像转换为OID

 <insert tableName="IMAGES">
        <column name="image_id" valueSequenceNext="image_id_seq"/> 
        <column name="name" value="some image name"/>
        <column name="content" valueComputed="lo_from_bytea(0, decode('DLxmEfVUC9CAmjiNyVphWw==', 'base64'))"/>
    </insert>


希望它能帮助别人

可能是JHipster/Liquibaset使用的高级类型。实际列类型是Bytea。您有没有尝试过的代码?我有,稍后我会回答自己的问题。可能是JHipster/Liquibaset使用的高级类型。实际列类型是Bytea。您有没有尝试过的代码?我有,稍后我会回答自己的问题。