hyb
2025-05-14 87453ffd761425b9f363a09a0f8fe07d770cb325
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
@File    : auxiliary_func.py
@Time    : 2022/12/6 15:56
@Author  : geekbing
@LastEditTime : -
@LastEditors : -
@Description : -
"""
import base64
import os
 
from backend.settings import BASE_DIR
 
 
def img_value():
    """
    获取图片换算值
    :return:
    """
    file_path = os.path.join(BASE_DIR, "test_data/images/attachment.jpg")
    file_value = get_file_value(file_path)
 
    return file_value
 
 
def get_file_value(file_path):
    """
    解析编码文件,生成file参数的值
    :param file_path: 文件路径
    :return:
    """
    # 以二进制格式读取文件内容
 
    with open(file_path, "rb") as f:
        content = f.read()
 
    content = base64.b64encode(content)
    suffix_name = file_path.split(".")[-1]
    # file参数格式:文件名后缀 + @ + 文件内容进行base64编码后的字符串
    file_value = suffix_name + "@" + content.decode()
 
    return file_value