add upyun upload file test
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
@@ -0,0 +1,19 @@
|
|||||||
|
local yun = require("upyun")
|
||||||
|
|
||||||
|
local config = {
|
||||||
|
user = "moicen", --授权操作员名称
|
||||||
|
passwd = "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN", --操作员密码
|
||||||
|
localFilePath = "/Users/liyong/Code/Lua/resty_functions/test_files_dir/r2d2.jpeg"
|
||||||
|
}
|
||||||
|
|
||||||
|
local upyun = yun:new(config)
|
||||||
|
|
||||||
|
local savePath = "huiwing/test/r2d2.jpeg"
|
||||||
|
local gmkerl = nil
|
||||||
|
local options = nil
|
||||||
|
|
||||||
|
local info, err = upyun:upload_file(savePath, gmkerl, options)
|
||||||
|
if not info then
|
||||||
|
ngx.say("failed to upload image file : " .. err)
|
||||||
|
return
|
||||||
|
end
|
||||||
@@ -270,6 +270,8 @@ local function _request(sock, method, path, headers, body, extra)
|
|||||||
local host = headers.Host
|
local host = headers.Host
|
||||||
if not sock then
|
if not sock then
|
||||||
return nil, "not initialized yet"
|
return nil, "not initialized yet"
|
||||||
|
else
|
||||||
|
print("Connect host : ", host)
|
||||||
end
|
end
|
||||||
|
|
||||||
sock:settimeout(5000)
|
sock:settimeout(5000)
|
||||||
@@ -280,6 +282,11 @@ local function _request(sock, method, path, headers, body, extra)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Build and send request header
|
-- Build and send request header
|
||||||
|
print("Debug header method : ", method)
|
||||||
|
print("Debug header path : ", path)
|
||||||
|
print("Debug header headers : ", headers)
|
||||||
|
print("Debug header extra : ", extra)
|
||||||
|
|
||||||
local header = _req_header(method, path, headers, extra)
|
local header = _req_header(method, path, headers, extra)
|
||||||
local bytes, err = sock:send(header)
|
local bytes, err = sock:send(header)
|
||||||
if not bytes then
|
if not bytes then
|
||||||
@@ -513,6 +520,7 @@ function _M.new(self, config)
|
|||||||
local passwd = config.passwd
|
local passwd = config.passwd
|
||||||
local endpoint = config.endpoint and tonumber(config.endpoint) + 1 or 1
|
local endpoint = config.endpoint and tonumber(config.endpoint) + 1 or 1
|
||||||
local author = config.author and lower(config.author) or nil
|
local author = config.author and lower(config.author) or nil
|
||||||
|
local localFilePath = config.localFilePath;
|
||||||
|
|
||||||
if not user or type(user) ~= "string" or user == "" then
|
if not user or type(user) ~= "string" or user == "" then
|
||||||
return nil, "invalid user"
|
return nil, "invalid user"
|
||||||
@@ -536,9 +544,11 @@ function _M.new(self, config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- file to be uploaded is stored in the request body
|
-- file to be uploaded is stored in the request body
|
||||||
read_body()
|
--read_body()
|
||||||
local content = get_body_data()
|
--local content = get_body_data()
|
||||||
local file = ngx.req.get_body_file()
|
--local file = ngx.req.get_body_file()
|
||||||
|
local file = localFilePath;
|
||||||
|
local content = nil;
|
||||||
if file then
|
if file then
|
||||||
local f, err = io.open(file, "r")
|
local f, err = io.open(file, "r")
|
||||||
if not f then
|
if not f then
|
||||||
@@ -549,9 +559,9 @@ function _M.new(self, config)
|
|||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
--if not content then
|
if not content then
|
||||||
-- return nil, "request body is expected"
|
return nil, "request body is expected"
|
||||||
--end
|
end
|
||||||
|
|
||||||
--TODO ngx.updatetime?
|
--TODO ngx.updatetime?
|
||||||
local date = http_time(time_sec())
|
local date = http_time(time_sec())
|
||||||
|
|||||||
Reference in New Issue
Block a user