我用 docker 跑了一个 minio
version: "3"
services:
public_minio:
container_name: public_minio
image: minio/minio
ports:
- "9000:9000" # client port
- "9002:9002" # console port
command: server /data --console-address ":9002" #指定容器中的目录 /data
environment:
MINIO_ACCESS_KEY: ponponon #管理后台用户名
MINIO_SECRET_KEY: ponponon #管理后台密码,最小8个字符
minio 的前端页面显示正常的,但是下载到本地的文件,变成蝌蚪文了
上传文件,我不是通过前端上传的,是写了一段 python 代码
import os
from loguru import logger
from pathlib import Path
from mark import BASE_DIR
import multiprocessing
import itertools
from typing import Generator, Callable
from concurrent.futures.thread import ThreadPoolExecutor
def upload(snapshot_filename: Path):
try:
from core.minio.crud import exist, upload, upload_file
# print(str(snapshot_filename))
_key = str(snapshot_filename).removeprefix('resource/')
if not exist(_key):
# with open(snapshot_filename, 'rb') as f:
upload_file(snapshot_filename, _key)
except Exception as error:
logger.exception(error)
# os.remove(image)
def process_func(snapshot_filenames: list[Path]):
try:
pool = ThreadPoolExecutor(max_workers=1)
assert isinstance(snapshot_filenames, list)
assert isinstance(snapshot_filenames[0], Path)
for snapshot_filename in snapshot_filenames:
pool.submit(upload, snapshot_filename)
pool.shutdown(wait=True)
except Exception as error:
logger.exception(error)
def gen(snapshot_filenames: list[Path]):
for snapshot_filename in snapshot_filenames:
yield snapshot_filename
if __name__ == "__main__":
snapshot_dir = Path(
'resource/video')
snapshot_filenames: list[Path] = []
for item in os.walk(snapshot_dir):
dirpath, dirnames, filenames = item
dirpath: str
dirnames: list[str]
filenames: list[str]
for filename in filenames:
snapshot_filenames.append(Path(dirpath)/filename)
snapshot_filenames = [
i for i in snapshot_filenames]
snapshot_filenames.sort()
logger.debug(f'一共有 {len(snapshot_filenames)} 个文件')
pool = multiprocessing.Pool(processes=1)
# snapshot_filenames = snapshot_filenames[:1]
logger.debug(f'snapshot_filenames len: {len(snapshot_filenames)}')
gg = gen(snapshot_filenames)
for _snapshot_filenames in iter(
lambda: list(itertools.islice(gg, 1000)),
[]
):
pool.apply_async(process_func, (_snapshot_filenames,))
logger.debug(f'投递完成')
pool.close()
pool.join()
这个问题,我写了一个 python 脚本复现
随便上传一个文件名中带有中文的文件
然后写了上面的代码
运行结果
可以看到,用 py 脚本请求,也是乱码
那么,如何解决呢?
先尝试一下给请求头加上
Accept-Charset: utf-8
但是不行
然后我去 minio 的 github issues 上看了看,发现没有什么有用的信息
我就想,或许这个问题已经在新版的 minio 中解决了
所以我就换了一个新版的 minio
然后问题就解决了
但是这个最新版虽然没有乱码了,但是引入了新的问题:chrome 可以下载文件,但是 firefox 无法下载文件
真是想吐槽一下:minio bug 真多