Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
5f0e701f
提交
5f0e701f
authored
5月 24, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [utils] 阿里云oss工具
上级
64da3c75
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
6 行删除
+16
-6
aliyun_oss.py
isc_video_record/utils/aliyun_oss.py
+16
-6
没有找到文件。
isc_video_record/utils/aliyun_oss.py
浏览文件 @
5f0e701f
import
os
import
os
import
oss2
import
oss2
import
urllib.request
from
functools
import
lru_cache
from
functools
import
lru_cache
from
dynaconf
import
settings
from
dynaconf
import
settings
from
oss2.exceptions
import
NoSuchKey
local_endpoint
=
'https://oss-cn-{}-internal.aliyuncs.com'
# 局域网配置
local_endpoint
=
'https://oss-cn-{}-internal.aliyuncs.com'
# 局域网配置
...
@@ -12,9 +14,11 @@ local_endpoint = config.get('endpoint', local_endpoint.format(region))
...
@@ -12,9 +14,11 @@ local_endpoint = config.get('endpoint', local_endpoint.format(region))
@lru_cache
()
@lru_cache
()
def
_get_bucket
():
def
_get_bucket
(
bucket_name
=
None
,
l_region
=
None
):
endpoint
=
'https://oss-cn-{}.aliyuncs.com'
.
format
(
l_region
or
region
)
if
l_region
else
local_endpoint
bucket_name
=
bucket_name
or
config
[
'bucket_name'
]
bucket
=
oss2
.
Bucket
(
oss2
.
Auth
(
config
[
'access_key_id'
],
config
[
'access_key_secret'
]),
bucket
=
oss2
.
Bucket
(
oss2
.
Auth
(
config
[
'access_key_id'
],
config
[
'access_key_secret'
]),
local_endpoint
,
config
[
'bucket_name'
]
)
endpoint
,
bucket_name
)
return
bucket
return
bucket
...
@@ -41,14 +45,14 @@ def oss_delete_file(origin_file):
...
@@ -41,14 +45,14 @@ def oss_delete_file(origin_file):
return
True
if
len
(
res
)
>
0
else
False
return
True
if
len
(
res
)
>
0
else
False
def
oss_batch_delete_files
(
files_list
):
def
oss_batch_delete_files
(
files_list
,
bucket_name
=
None
,
l_region
=
None
):
""" 批量删除云端文件
""" 批量删除云端文件
"""
"""
bucket
=
_get_bucket
()
bucket
=
_get_bucket
(
bucket_name
,
l_region
)
bucket_files
=
[]
bucket_files
=
[]
for
origin_file
in
files_list
:
for
origin_file
in
files_list
:
if
origin_file
.
startswith
(
'http://'
)
or
origin_file
.
startswith
(
'https://'
):
if
origin_file
.
startswith
(
'http://'
)
or
origin_file
.
startswith
(
'https://'
):
bucket_files
.
append
(
origin_file
.
split
(
'/'
)[
-
1
]
)
bucket_files
.
append
(
'/'
.
join
(
origin_file
.
split
(
'/'
)[
3
:])
)
else
:
else
:
bucket_files
.
append
(
origin_file
)
bucket_files
.
append
(
origin_file
)
...
@@ -60,11 +64,15 @@ def oss_download_file(origin_file, local_file):
...
@@ -60,11 +64,15 @@ def oss_download_file(origin_file, local_file):
"""
"""
下载视频文件
下载视频文件
"""
"""
old_origin_file
=
origin_file
try
:
bucket
=
_get_bucket
()
bucket
=
_get_bucket
()
if
origin_file
.
startswith
(
'http://'
)
or
origin_file
.
startswith
(
'https://'
):
if
origin_file
.
startswith
(
'http://'
)
or
origin_file
.
startswith
(
'https://'
):
origin_file
=
origin_file
.
split
(
'/'
)[
-
1
]
origin_file
=
'/'
.
join
(
origin_file
.
split
(
'/'
)[
3
:])
bucket
.
get_object_to_file
(
origin_file
,
local_file
)
bucket
.
get_object_to_file
(
origin_file
,
local_file
)
except
NoSuchKey
:
urllib
.
request
.
urlretrieve
(
old_origin_file
,
local_file
)
return
local_file
return
local_file
...
@@ -73,3 +81,5 @@ if __name__ == '__main__':
...
@@ -73,3 +81,5 @@ if __name__ == '__main__':
# print(oss_download_file('https://test-qzwjtest.oss-cn-hangzhou.aliyuncs.com/test-2.mp4', 't.mp4'))
# print(oss_download_file('https://test-qzwjtest.oss-cn-hangzhou.aliyuncs.com/test-2.mp4', 't.mp4'))
# print(oss_delete_file('https://test-qzwjtest.oss-cn-hangzhou.aliyuncs.com/test-2.mp4'))
# print(oss_delete_file('https://test-qzwjtest.oss-cn-hangzhou.aliyuncs.com/test-2.mp4'))
oss_download_file
(
'D00268229_2020-10-23_14-07-13.mp4'
,
'/tmp/v3/videos/D00268229_2020-10-23_14-07-13.mp4'
)
oss_download_file
(
'D00268229_2020-10-23_14-07-13.mp4'
,
'/tmp/v3/videos/D00268229_2020-10-23_14-07-13.mp4'
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论