add download message image
continuous-integration/drone/push Build is passing

This commit is contained in:
jianxin committed 2024-01-17 17:46:58 +08:00
1 parent cdfe31bafc
commit dab827390c
1 file changed
+7 -6
+7 -6
View File
@@ -32,10 +32,10 @@ def get_message_resource(client, message_id, file_key, file_type, save_dir):
# 处理业务结果 # 处理业务结果
# 处理业务结果 # 处理业务结果
file_path = os.path.join(save_dir, file_key) file_path = os.path.join(save_dir, file_key)
f = open(file_path, "wb") with open(file_path, "wb") as f:
f.write(response.file.read()) f.write(response.file.read())
f.close()
return file_path return file_path
@@ -45,7 +45,7 @@ def upload_media(client, file_path, parent_type, parent_node):
_, filename = os.path.split(file_path) _, filename = os.path.split(file_path)
file_size = os.path.getsize(file_path) file_size = os.path.getsize(file_path)
file_bin = open(file_path) with open(file_path) as f:
request: UploadAllMediaRequest = ( request: UploadAllMediaRequest = (
UploadAllMediaRequest.builder() UploadAllMediaRequest.builder()
.request_body( .request_body(
@@ -54,13 +54,12 @@ def upload_media(client, file_path, parent_type, parent_node):
.parent_type(parent_type) .parent_type(parent_type)
.parent_node(parent_node) .parent_node(parent_node)
.size(file_size) .size(file_size)
.file(file_bin) .file(f)
.build() .build()
) )
.build() .build()
) )
file_bin.close()
# 发起请求 # 发起请求
option = ( option = (
@@ -68,7 +67,9 @@ def upload_media(client, file_path, parent_type, parent_node):
.user_access_token("u-dF0r5rD5BcUFhORI38zmlk1l61TBghPzry00gl.82Haz") .user_access_token("u-dF0r5rD5BcUFhORI38zmlk1l61TBghPzry00gl.82Haz")
.build() .build()
) )
response: UploadAllMediaResponse = client.drive.v1.media.upload_all(request, option) response: UploadAllMediaResponse = client.drive.v1.media.upload_all(
request, option
)
# 处理失败返回 # 处理失败返回
if not response.success(): if not response.success():