Saeid
Saeid

Reputation: 623

How to get file size from file path with js?

I want to get the size of a file from this path:

my-path/filename

How can I get the size of this file?

Upvotes: 1

Views: 467

Answers (1)

NetByMatt
NetByMatt

Reputation: 719

Use the fetch() method and only set the request method to HEAD.

    const fetchResponse = await fetch(src, { method: 'HEAD' });
    const size = fetchResponse.headers.get('content-length');

Beware, it will return a number represented as a string.

Upvotes: 2

Related Questions