简体   繁体   English

将映像存储在Hbase中,丢失元数据和Exif

[英]Store image in Hbase loss of Meta data and Exif

Uploading an image to hbase using Java program, after retrieving the image I found there is difference in file size eventually increased and most of Exif and Meta data loss (GPS location data, camera details, etc..) 使用Java程序将图像上传到hbase,在检索图像后,我发现文件大小的差异最终会增加,并且大部分Exif和Meta数据丢失(GPS位置数据,相机详细信息等)。

Code : 代码:

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);

How to store and retrieve a Image with out any change / loss? 如何存储和检索没有任何更改/丢失的图像?

Please try using SerializationUtils from Apache Commons Lang. 请尝试使用来自Apache Commons Lang的SerializationUtils

Below are methods 以下是方法

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.

While storing in to hbase you can store byte[] which was returned from serialize. 当存储到hbase中时,您可以存储从序列化返回的byte []。 While getting the Object you can type cast to corresponding object for ex: File object and can get it back. 在获取对象时,您可以将类型转换为对应的对象,例如ex:File对象,然后可以将其取回。

Most likely you are just over-complicating things. 您很可能只是使事情变得过于复杂。 :-) :-)

The reason why you are losing the Exif and other metadata, is that the ImageIO convenience methods ImageIO.read(...) and ImageIO.write(...) does not preserve metadata. 之所以丢失Exif和其他元数据,是因为ImageIO便捷方法ImageIO.read(...)ImageIO.write(...)不会保留元数据。 The good news is, they are not needed. 好消息是,不需要它们。

As you seem to already have the image data from the MultipartFile , you should simply store that data (the byte array) in the database, and you will store exactly what the user uploaded. 好像您已经从MultipartFile获取图像数据一样,您应该仅将数据(字节数组)存储在数据库中,并且将确切存储用户上传的内容。 No difference in file size, and metadata will be untouched. 文件大小没有差异,并且元数据将保持不变。

Your code above doesn't compile for me, and I'm no HBase expert, so I just leave that out (as you have already been able to store an image, to see the size/quality difference and metadata loss, I assume you know how to do that :-) ). 您上面的代码无法为我编译,我也不是HBase专家,因此我将其排除在外(因为您已经能够存储图像,以查看大小/质量差异和元数据丢失,所以我假设您知道该怎么做:-))。 But here's the basics: 但是这里是基础:

public ArrayList<Object> uploadImagesToHbase(MultipartFile uploadedFileRef) {
    byte[] bytes = uploadedFileRef.getBytes();

    // Store the above "bytes" byte array in HBase *as is* (no ImageIO)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM