1

How to get size of media?

asked 2016-09-20 10:20:53 +0800

psingh gravatar image psingh flag of India
963 8

I am using Zk dropupload to upload the file but I have some constraints to upload the file less than 2 gb. I want to restrict the user not to upload the file greater than 2 gb but not by using dropupload maxsize="5120". It should be done on onUpload event. Is there any other way to get the uploaded file size in less time.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-09-20 11:57:04 +0800

IngoB gravatar image IngoB flag of Germany
256 6

updated 2016-09-20 11:57:30 +0800

otherwise you can count the written bytes and stop it after 2gb

final long MAX_SIZE = 2147483648L;
long currentSize = 0;
byte[] buffer = new byte[1024 * 8];
for (int count; (count = inputStream.read(buffer)) != -1;) {        
    currentSize += count;
    if (currentSize >= MAX_SIZE) {
        System.out.println("too big!");
        break;
    }
    outputStream.write(buffer, 0, count);
}
link publish delete flag offensive edit
0

answered 2016-09-20 10:46:48 +0800

Darksu gravatar image Darksu
1991 1 4

Hello psingh,

Fastest solution i can think of is to create a temporary file and get the file size using the command:

file.length();

Reference: https://www.mkyong.com/java/how-to-create-temporary-file-in-java/

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

I am already using same thing but I need faster way without writing such lines of code.

psingh ( 2016-09-20 10:54:46 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-09-20 10:20:53 +0800

Seen: 32 times

Last updated: Sep 20 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More