How to get browse file size in AEM 6.3 | Community
Skip to main content
anoopo70540109
New Participant
September 14, 2017
Solved

How to get browse file size in AEM 6.3

  • September 14, 2017
  • 4 replies
  • 2688 views

Hi All,

I have created one download component in which i want to show the file size along with download description. I am able to get the file size when i am doing drag and drop the file(pdf) from DAM by using asset.getOriginal().getsize(). But i am unable to get the size of file which I am browsing from my local machine. Is there any way to get the size of browse file as well ?.

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AnkurAhlawat-1

I think you want to get file size as metadata that you want to upload from your local file system, just to display to user that current file size it xxxx.

You can leverage plain html5 feature. Just create a listener on for <input type="file" id="files-upload">

var filesUpload = document.getElementById("files-upload");

filesUpload.addEventListener("change", function() {

     alert(this.file.size);

}

Still i am not fully aware of your use case. Let me know if you are trying to achieve some thing else.

4 replies

kautuk_sahni
Employee
September 18, 2017

Adding Demo for What Ankur shared:- JS Bin - Collaborative JavaScript Debugging

Note:- Only need to check is the browser support.

~kautuk

Kautuk Sahni
AnkurAhlawat-1
AnkurAhlawat-1Accepted solution
New Participant
September 17, 2017

I think you want to get file size as metadata that you want to upload from your local file system, just to display to user that current file size it xxxx.

You can leverage plain html5 feature. Just create a listener on for <input type="file" id="files-upload">

var filesUpload = document.getElementById("files-upload");

filesUpload.addEventListener("change", function() {

     alert(this.file.size);

}

Still i am not fully aware of your use case. Let me know if you are trying to achieve some thing else.

joerghoh
Employee
September 15, 2017

What do you mean with "browse file"? Do you want to get the size of the HTML file during the process of rendering the file? Or the size of other HTML files you are linking to?

Jörg

smacdonald2008
New Participant
September 15, 2017

TO do this - you would need to write a custom HTL component that also has a Java backend. You can create a POJO that holds DAM Asset attributes and the file size being one of them. Then you would use Java logic to get the file size and use HTL to render all of the attributes including the file size