I am storing images that range from 1mb and maximum 7mb in a MySQL database. For this I have created a table with a field of type MEDIUMBLOB that has a capacity of 16,777,215 bytes which is the same 16mb. When I save images of up to 2.2mb it is stored perfectly, but when I save larger images but that do not exceed 7mb I get the following error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'image' at row 1
This is the definition of the image field in my entity Image:
@Entity
@Access(AccessType.FIELD)
@Table(name = "Imagen")
@XmlRootElement
public class Imagen implements Serializable {
// otros campos
@Lob
@Column(name = "imagen", columnDefinition = "mediumblob")
private byte[] imagen;
// getters and setters
}
The table Image:
CREATE TABLE Imagen (
id INT(10) NOT NULL AUTO_INCREMENT,
-- Otros campos
imagen MEDIUMBLOB,
type VARCHAR(10) COLLATE UTF8_SPANISH_CI,
PRIMARY KEY (id)
);
For query and persistence operations use spring-data-jpa.
Note: The development environment is maven + javafx + spring + mysql