阿里云oss_遍历文件,下载文件,读取内容

[复制链接]
查看2715 | 回复7 | 2021-12-3 20:30:47 | 显示全部楼层 |阅读模式
使用懒人精灵IDE,访问阿里云oss连接,实现下载文件,读取文件内容.无需验证直接获取.

首先在阿里云oss创建一个,Bucket对象.


设置读取权限为:公共读写.


设置Bucket 授权策略:新增授权-匿名账号-完全控制-确定

授权.png 设置.png 1.png

之后就是执行懒人精灵程序.

阿里云oss.lua 文件源码:
  1. --下载 = 'https://aitlo.oss-cn-shenzhen.aliyuncs.com/%E4%B9%9D%E6%B8%B8%E6%B8%B8%E6%88%8F%E8%B4%A6%E5%8F%B7.txt'

  2. function ossServerFile(url)
  3.         -- 获取oss服务端文件名
  4.         local ret,code  = httpGet(url)
  5.         local fileTab = {}
  6.         for k,v in pairs(splitStr(ret,"<Key>"))do
  7.                 for j,n in pairs(splitStr(v,"</Key>"))do
  8.                         
  9.                         if string.find(n,"<",1) then
  10.                                 
  11.                         else
  12.                                 table.insert(fileTab,n)
  13.                                 
  14.                         end
  15.                 end
  16.         end
  17.         print("阿里云oss服务器文件列表:",fileTab)
  18.         return fileTab
  19. end

  20. function download(url,filename,savename)
  21.         -- 下载文件
  22.         local path = "/mnt/sdcard/懒人精灵下载"
  23.         if fileExist(path) == false then
  24.                
  25.                 print(mkdir(path))
  26.                
  27.         end
  28.         local res = downloadFile(string.format("%s/%s",url,filename),string.format("/mnt/sdcard/懒人精灵下载/%s",savename))
  29.         if res == 0 then
  30.                 print(string.format("文件已下载:/mnt/sdcard/懒人精灵下载/%s",savename))
  31.         end
  32. end

  33. function upload(url,filename)
  34.         -- 上传文件
  35.         local res = uploadFile(url,"/mnt/sdcard/test.txt")
  36.         print(res)
  37. end

  38. function GetOssFileData(url,filename)
  39.         -- 获取oss文件内容
  40.         local ret,code = httpGet(string.format("%s/%s",url,filename))
  41.         print("已读取内容:",ret)
  42.         return ret
  43. end
  44. -- url 为 阿里云oss Bucket名称+Endpoint地域
  45. url = "https://aitlo.oss-cn-shenzhen.aliyuncs.com/"

  46. -- 遍历oss文件
  47. fileTab = ossServerFile(url)

  48. -- 下载oss文件
  49. download(url,"合鑫真机连接地址.txt","合鑫真机连接地址.txt")

  50. -- 读取oss文件内容
  51. GetOssFileData(url,"阿里云oss测试文件.txt")

复制代码
运行结果图片:
3.png




回复

使用道具 举报

qq9451045 | 2021-12-4 00:27:32 | 显示全部楼层
6666666666

安卓脚本,苹果脚本
脚本定制接单;自动化操作;手动能完成的都能做;
Q: 9451045
回复

使用道具 举报

ca0111 | 2021-12-4 22:18:07 | 显示全部楼层
你怎么这么溜
回复

使用道具 举报

adws18 | 2021-12-6 11:40:13 | 显示全部楼层
收藏先了。
回复

使用道具 举报

tianquan514 | 2022-2-3 19:18:24 | 显示全部楼层
阿里云oss.lua 文件源码
回复

使用道具 举报

yinjiantuan | 2022-2-4 16:22:02 | 显示全部楼层
值得学些
回复

使用道具 举报

xywl | 2022-4-8 12:31:26 | 显示全部楼层
666收藏了
回复

使用道具 举报

jzl6668 | 2022-5-19 19:33:45 | 显示全部楼层


谢谢大佬分享 !
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则