Files
resty_functions/scripts/test_upyun_upload.lua
2024-01-07 21:19:02 +08:00

58 lines
1.5 KiB
Lua

-- 指定模块引用目录,否则无法加载同目录下的其他文件
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
--package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local yun = require("lib.upyun")
local cjson = require "cjson"
local function upyun_upload_file()
local config = {
user = ngx.var.upyun_operator,
passwd = ngx.var.upyun_password,
localFilePath = "/file_upload/abc.mp3"
}
local upyun = yun:new(config)
--local bucket = ngx.var.upyun_bucket
local bucket = "moicen"
local directory = 'test'
local savePath = bucket .. "/" .. directory .. "/chunxiao.mp3"
local info, err = upyun:upload_file(savePath, nil, nil)
if not info then
ngx.say("failed to upload file : " .. err)
return
else
ngx.say(cjson.encode(info))
end
end
local function upyun_remove_file()
local config = {
user = ngx.var.upyun_operator,
passwd = ngx.var.upyun_password,
localFilePath = nil
}
local upyun = yun:new2(config)
--local bucket = ngx.var.upyun_bucket
local bucket = "moicen"
local directory = 'test'
local removePath = bucket .. "/" .. directory .. "/chunxiao.mp3"
local info, err = upyun:remove_file(removePath)
if not info then
ngx.say("failed to remove file : " .. err)
return
else
ngx.say(cjson.encode(info))
end
end
upyun_upload_file()
--upyun_remove_file()