You need to sign in to do that
Don't have an account?

Can you check why im off a little when calculating inputFile size?
for example when i upload a file that is 4.89 KB according to windows file properties, my output below gives me 4.74 KB. Its always real close and a little under.
String s = Document.body.toString(); Decimal byteCount = s.length(); Decimal kb_dec = byteCount / 1000; Decimal kb_divDec = byteCount.divide(1000, 2, System.RoundingMode.UP); double mb = kb_dec / 1000; Decimal mb_divDec = kb_dec.divide(1000, 2, System.RoundingMode.UP); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'The image size is... ' +mb_divDec +' MBs, ' +kb_divDec+' KBs, '+byteCount+' bytes.'));
1KB is 1024 bytes, not 1000 bytes. (unless you manufacture disk drives)
All Answers
1KB is 1024 bytes, not 1000 bytes. (unless you manufacture disk drives)
Thank you SimonF. i also couldnt get it right until using body.size() instead of getting the string length() of the body.