forked from azurewang/Nginx_Lua-FastDFS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastdfs.lua
More file actions
59 lines (59 loc) · 1.57 KB
/
fastdfs.lua
File metadata and controls
59 lines (59 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- main
local fastdfs = require('resty.fastdfs')
local fdfs = fastdfs:new()
fdfs:set_tracker("192.168.85.249",22122)
fdfs:set_timeout(1000)
fdfs:set_tracker_keepalive(0, 100)
fdfs:set_storage_keepalive(0, 100)
local method = ngx.var.arg_method
if method == 'delete' then
local fileid = ngx.var.arg_fileid
local res = fdfs:do_delete(fileid)
if not res then
ngx.say("ERR")
elseif res.status == 0 then
ngx.say("OK")
else
ngx.say("ERR:(" .. res.status .. ")")
end
elseif method == 'upload' then
local ext_name = ngx.var.arg_ext_name
local res = fdfs:do_upload(ext_name)
if not res then
ngx.say("ERR")
elseif res then
ngx.say(string.format("%s/%s",res.group_name, res.file_name))
else
ngx.exit(406)
end
elseif method == 'upload_appender' then
local ext_name = ngx.var.arg_ext_name
local res = fdfs:do_upload_appender(ext_name)
if not res then
ngx.say("ERR")
elseif res then
ngx.say(string.format("%s/%s",res.group_name, res.file_name))
else
ngx.exit(406)
end
elseif method == 'download' then
local fileid = ngx.var.arg_fileid
local data = fdfs:do_download(fileid)
if not data then
ngx.say("ERR")
else
ngx.print(data)
end
elseif method == 'append' then
local fileid = ngx.var.arg_fileid
local res = fdfs:do_append(fileid)
if not res then
ngx.say("ERR")
elseif res.status == 0 then
ngx.say("OK")
else
ngx.say("ERR:(" .. res.status .. ")")
end
else
ngx.say('not input method')
end