How to get file type extension from byte[] (Blob). I’m reading files from DB to byte[] but i don’t know how to automatically detect file extension.
Blob blob = rs.getBlob(1);
byte[] bdata = blob.getBytes(1, (int) blob.length());
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You mean you want to get the extension of the file for which the blob store the content? So if the BLOB stores the content of a jpeg-file, you want
"jpg"?That’s generally speaking not possible. You can make a fairly good guess by using some heuristic such as Apache Tikas content detection.
A better solution however, would be to store the mime type (or original file extension) in a separate column, such as a
VARCHAR.