Reputation: 623
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
Reputation: 719
Use the fetch() method and only set the request method to HEAD.
fetch()
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