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
+33 -32
+33 -32
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,39 +45,40 @@ 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(
UploadAllMediaRequestBody.builder() UploadAllMediaRequestBody.builder()
.file_name(filename) .file_name(filename)
.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 = (
lark.RequestOption.builder() lark.RequestOption.builder()
.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():
lark.logger.error(
f"client.drive.v1.media.upload_all failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}"
) )
return
# 处理业务结果 # 处理失败返回
lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if not response.success():
lark.logger.error(
f"client.drive.v1.media.upload_all failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}"
)
return
return response.data.file_token # 处理业务结果
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
return response.data.file_token