完整脚本示例

local ts = require("ts")
local json = ts.json
--企业版库为企业版专用库请勿在除企业版外的产品使用,此库已内置,无需下载
--如果提示没有 ts_enterprise_lib 库请重启企业版客户端服务再试
ts_enterprise_lib = require("ts_enterprise_lib")
assert(ts_enterprise_lib,"无法引入企业专用库")
local cloud_file_name = "/a1/1.txt"
local file_data = "123"                     --需要添加的文件数据
local timeout_seconds = 5;                  --超时秒数,数据较大时,适当延长
--创建 a1 文件夹及 1.txt 文件
bool = ts_enterprise_lib:cloud_file_new(cloud_file_name)
if bool then
    dialog("创建成功")
    --在 1.txt 文件中写入 123
    local ok,err = ts_enterprise_lib:cloud_file_save(cloud_file_name,file_data,timeout_seconds)
    if ok then 
        dialog("写入成功")
        --读取 1.txt 文件内容
        ok,err = ts_enterprise_lib:cloud_file_load(cloud_file_name,timeout_seconds)
        if ok then
            dialog("读取成功,文件内容:"..err)
            -- 下载 a1 文件夹下的 1.txt 到手机上
            local local_file = userPath().."/res/1.txt"  
            local ok,err = ts_enterprise_lib:cloud_file_pull(local_file,cloud_file_name,timeout_seconds)
            if ok then
                dialog("下载成功")
                --将 1.txt 文件重命名为 2.txt
                ret = ts_enterprise_lib:cloud_file_rename("/a1/1.txt","2")
                if  ret then
                    dialog("重命名成功")
                    -- 将 1.txt 文件上传到 a1 文件夹下
                    local ok,err = ts_enterprise_lib:cloud_file_push(local_file,cloud_file_name,timeout_seconds)
                    if ok then
                        dialog("上传成功")
                        --获取 a1 文件夹下的文件
                        dialog("a1 文件夹下存在文件:"..json.encode({ts_enterprise_lib:cloud_file_list("/a1/")}))
                    else
                        dialog("上传失败:"..err)
                    end
                else
                    dialog("重命名失败")
                end
            else
                dialog("下载失败,失败原因:"..err)
            end
        else
            dialog("读取失败,失败原因:"..err)
        end
    else
        dialog("写入失败,失败原因:"..err)
    end
else
    dialog("创建失败")
end

注意事项

  • 错误返回 timeout 请在获取数据前增加代码 ts_enterprise_lib.timeout = 20 或者增加参数: timeout_seconds 的时间,如果仍返回 timeout 请修改为 20 以上的数字
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""