Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:38:23+00:00 2026-06-10T09:38:23+00:00

I have a function that takes two arguments: entry , a file entry (from

  • 0

I have a function that takes two arguments: entry, a file entry (from a drag and drop source), and fileName, the name of said file.

I’m not sure if this helps, but entry is declared as:

var entry = evt.dataTransfer.items[i].webkitGetAsEntry();

I want to create an array that describes information about this entry, that array includes the file name, file size, a file size that is represented in a different unit, and the unit being used to represent said file. I print my array to the console at two different points, once inside of the .file method (I apologize if I’m using incorrect terminology) and once more outside. The console doesn’t print a value for the array when it is outside of the .file method.

Could I please get help on how to fix this and also why this happens? I declare my variable outside of the .file method so I thought my variable scoping was correct, but apparently this is not so.

Here is my function:

function getFileSize(entry,fileName)
{
    var fileData = [];
    var i = 0;
    var byteSize = ['B','kB','MB','GB','TB'];

    fileData.push(fileName);

    entry.file(function(file)
    {
        var fsize = file.size;
        var i = 0;
        fileData.push(fsize);

        while(fsize > 1024)
        {
            fsize = (fsize / 1024);
            i++;
        }

        fileData.push(fsize.toFixed(2));
        fileData.push(byteSize[i]);

        console.log(fileData);
    });

    console.log(fileData);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:38:24+00:00Added an answer on June 10, 2026 at 9:38 am

    The call to .file() is asynchronous. The fileData hasn’t been populated yet, when the last console.log(fileData) is called. If you want to return fileData to the caller,
    you’ll need to make getFileSize() async as well:

    function getFileSize(entry, fileName, callback) {
      ...
      var fileData = [];
    
      entry.file(function(f) {
        ...
        callback(fileData);
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have need for a function pointer that takes two arguments and returns a
I have a function that takes variadic arguments, that I obtain from func_get_args() .
I have a function that takes two arguments, the first one $methodName being a
I need to run a function that takes two arguments several times. I have
I have a SQL function called get_forecast_history(integer,integer) that takes two arguments, a month and
I have this function that takes two arguments. They are arrays in the [r,
I have written a function in python that takes two arguments one of which
I have written a function that takes two arguments and returns a SETOF result.
I have a function called workForThread, that takes two arguments, and returns void. I
I have a function that takes 2 parameters : 1 = XML file, 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.