Skip to content

Instantly share code, notes, and snippets.

@DepthDeluxe
Created December 1, 2016 21:43
Show Gist options
  • Save DepthDeluxe/94fe9547d13b50a3834a38dd7993a030 to your computer and use it in GitHub Desktop.
Save DepthDeluxe/94fe9547d13b50a3834a38dd7993a030 to your computer and use it in GitHub Desktop.
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;
}
}
@DepthDeluxe
Copy link
Author

Example: /util/display_filesize_bytes?filename=test.txt will return the size of test.txt. Will return 500: Internal Server Error if the file does not exist or query string does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment