How to get file size from an uploaded File

  • 23 April 2015
  • 2 replies
  • 38 views

Badge

Hello Guys,

       I use file attachment control in smartforms.Please let me know, how to get file size from an uploaded File.

   Thanks,

 


2 replies

Userlevel 1
Badge +8

Hi BabyDev

 

There doesn't appear to be anyway to access this information OOB. The only way I can think is to implement some Javascript to retreive the attachment control's title attribute. The title attribute contains the file name, MIME Type and data size delimited by forward slashes. If you can retrieve the title for the HTML element using Javascript (perhaps by targeting the class if you only have one control) then you could possibly parse out the bit you want from the title.

 

Example HTML snippet for attachment control:

 

<label for="00000000-0000-0000-0000-000000000000_74408c28-492b-5909-cbff-7a100aff9527_file-inputId" style="height:54px;" class="file-label" title="TEST1.docx / (Microsoft Office Word Document) / 22.56 KB">&nbsp;</label>

Userlevel 5
Badge +16

Dear,

 

According to  @Andrew_Blinco suggestion here's JS does what you want to achieve:

 

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<label for="00000000-0000-0000-0000-000000000000_ee2ae30b-d23f-cf88-9647-359a4d847577_file-inputId" style="height:54px;" class="file-label" title="Hover.txt / (Text Document) / 8.16 KB">&nbsp;</label>


<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
var x = document.getElementsByTagName("label")[0].getAttribute("title");
var n = x.lastIndexOf("/");
var s = x.substring(n+1);
document.getElementById("demo").innerHTML = s;

}
</script>

</body>
</html>

you just need to modify it, I'm setting the result in <p> tag, add your datalabe and get it's ID through INSPECT ELEMENT from the browser so you can set it's innerHTML 

 

RESULT:

 

12029iC172006F7C667244.png

Reply