I have a web app that is connected to a mySQL DB in BLOB Format, and there are some files stored in the DB, how can I fetch their sizes and add them to a new column in the table I'm using ? And what is the best approach to get file size of an uploaded file in JAVA ?!
Asked
Active
Viewed 263 times
0
-
How do you get new uploaded files ? You can use `File.length()`. – Gaël J Jan 04 '16 at 15:53
-
And what is your MySQL data type ? If `BLOB`, then use `OCTET_LENGTH(your_column_name)` statement (http://stackoverflow.com/questions/10648809/calculating-total-data-size-of-blob-column-in-a-table). – Gaël J Jan 04 '16 at 15:55
-
Yes it is BLOB... Will try that method thank you – WT86 Jan 04 '16 at 16:08
-
@Gaël Does it matter if it was BLOB or not? – WT86 Jan 04 '16 at 16:09
-
File size is in Bits correct ? – WT86 Jan 04 '16 at 16:23
2 Answers
1
For your new records that will be processed in Java you can use File.length()
if you're working with a File
object.
And for existing records, you can use OCTET_LENGTH(your_column_name)
statement (source: Calculating total data size of BLOB column in a table) which will give you the size in bytes.
0
select file_name, Octet_length(blob_colume) as "Size in Bytes" from Table_name;

Adarsh Gangadharan
- 653
- 4
- 10