增加上传数据
This commit is contained in:
@@ -95,7 +95,53 @@ function M.upload_file(config,remote_dir,local_filepath,auto_remove)
|
||||
end
|
||||
return false,result
|
||||
end
|
||||
function M.upload_data(config,remote_dir,data,ext)
|
||||
|
||||
if #data == 0 then
|
||||
return false,"数据为空"
|
||||
end
|
||||
local filename = fw.make_software_guid().."."..ext
|
||||
|
||||
local dirpath = ""
|
||||
|
||||
for dir, ext_list in pairs(M.ext_dirpath) do
|
||||
for _, ext_type_ext in ipairs(ext_list) do
|
||||
if ext_type_ext == ext then
|
||||
dirpath = dir
|
||||
break
|
||||
end
|
||||
end
|
||||
if dirpath ~= "" then
|
||||
break
|
||||
end
|
||||
end
|
||||
if dirpath == "" then
|
||||
return false,"不支持的文件格式,ext: "..ext
|
||||
end
|
||||
|
||||
if remote_dir == nil or remote_dir == "" then
|
||||
remote_dir = ""
|
||||
else
|
||||
remote_dir = remote_dir.."/"
|
||||
end
|
||||
|
||||
local cos_filepath = remote_dir .. dirpath.."/"..filename
|
||||
local oss = aliyun_oss.new()
|
||||
|
||||
|
||||
local result = oss:updata(
|
||||
config.endpoint,
|
||||
config.access_key_id,
|
||||
config.access_key_secret,
|
||||
config.bucket_name,
|
||||
cos_filepath,
|
||||
data
|
||||
)
|
||||
if result == "" then
|
||||
return true,cos_filepath
|
||||
end
|
||||
return false,result
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user