Created
December 1, 2016 21:43
-
-
Save DepthDeluxe/94fe9547d13b50a3834a38dd7993a030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location /util { | |
allow all; | |
default_type 'text\plain'; | |
root /dev/null; | |
location /util/display_filesize_bytes { | |
set_by_lua $my_var ' | |
function fsize(filename) | |
local file = io.open(filename, "r") | |
local size = file:seek("end") | |
return size | |
end | |
function find_filename(query_string) | |
value, garbage_and = string.match(query_string, "filename=(.+)(&?)") | |
return value | |
end | |
return fsize("/mnt/" .. find_filename(ngx.var.query_string))'; | |
return 200 $my_var; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
/util/display_filesize_bytes?filename=test.txt
will return the size oftest.txt
. Will return500: Internal Server Error
if the file does not exist or query string does not exist