如何使用 Lua 从 URL 中获取文件大小?

我想从上传到 URL 中的文件中获取文件大小。

我有一幅图片的 URL。 我想使用 Lua 中的 URL 获取它的大小,但我不知道怎么做

谢谢。

点赞
用户6834680
用户6834680
```lua
function get_resource_size(url)
   local pipe = io.popen('wget -S --spider --no-check-certificate "'..url..'" 2>&1')
   local size = pipe:read"*a":match"Content%-Length: (%d+)"
   pipe:close()
   return size and tonumber(size)
end

print(get_resource_size(
   "https://www.gravatar.com/avatar/282ad8d2c96e9b753bde22ac6ca0918b?s=32&d=identicon&r=PG"
))

你的头像大小为2074个字节。

2017-02-22 12:29:21