How insert image in room persistence library?

后端 未结 3 2072
轮回少年
轮回少年 2020-12-13 09:23

I am using room persistence library for my android application, Now I have to insert image in my db. I successfully define @Entity for the primitive data type. and also thro

3条回答
  •  死守一世寂寞
    2020-12-13 10:13

    It is usually not recommended to store image data into the database. But however if it is required for your project then you can do so.

    Image data are usually stored into db using BLOB data type, Room also provide support for BLOB data type Documentation

    You can declare your entity class as mentioned below to store Image data.

    @Entity(tableName = "test")
    public class Test{
    
    @PrimaryKey
    @ColumnInfo(name = "_id")
    private int id;
    
    @ColumnInfo(typeAffinity = ColumnInfo.BLOB)
    private byte[] image;
    }
    

提交回复
热议问题