فهرست منبع

增加上传数据

a158 8 ماه پیش
والد
کامیت
a82b77d02e
1فایلهای تغییر یافته به همراه46 افزوده شده و 0 حذف شده
  1. 46 0
      target/aliyun/oss.lua

+ 46 - 0
target/aliyun/oss.lua

@@ -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