使用 Java 程序将图像上传到 hbase,在检索图像后我发现文件大小存在差异最终增加并且大部分 Exif 和 Meta 数据丢失 (GPS 位置数据、相机详细信息等。)
代码:
public ArrayList<Object> uploadImagesToHbase(MultipartFile uploadedFileRef){
byte[] bytes =uploadedFileRef.getBytes();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", outputStream);
HBaseAdmin admin = new HBaseAdmin(configuration);
HTable table = new HTable(configuration, "sample");
Put image = new Put(Bytes.toBytes("1"));
image.add(Bytes.toBytes("DataColumn"), Bytes.toBytes(DataQualifier), bytes);
table.put(image);
如何在不改变/丢失的情况下存储和检索图像?
最佳答案
请尝试使用 SerializationUtils来自 Apache Commons Lang。
方法如下
static Object clone(Serializable object) //Deep clone an Object using serialization.
static Object deserialize(byte[] objectData) //Deserializes a single Object from an array of bytes.
static Object deserialize(InputStream inputStream) //Deserializes an Object from the specified stream.
static byte[] serialize(Serializable obj) //Serializes an Object to a byte array for storage/serialization.
static void serialize(Serializable obj, OutputStream outputStream) //Serializes an Object to the specified stream.
在存储到 hbase 时,您可以存储从序列化返回的 byte[]。 在获取对象时,您可以将类型强制转换为相应的对象,例如:文件对象,然后可以取回它。
关于java - 在Hbase中存储图片丢失Meta数据和Exif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36952192/