minio搭建图床 配合typora实现写博客图片自动上传
1、搭建minio
查看博客:http://www.weinigb.cn/#/info?blogOid=32
2、使用脚本(python)
使用之前需要添加依赖,分别需要添加 minio requests 依赖
pip install minio
# 也可以百度自己查看如何安装 (因为博主不是python的所有可能会存在失误)
pip install requests
ps:博主是使用 pycharm 自动安装的依赖
2.1、脚本
import os
import time
import uuid
import sys
import requests
from minio import Minio
from minio.error import ResponseError
import warnings
ip = ""
port = ""
accessKey = ""
secretKey = ""
isSSl = False
bucket = ""
warnings.filterwarnings('ignore')
images = sys.argv[1:]
minioClient = Minio(ip+":"+port,
access_key=accessKey, secret_key=secretKey, secure=isSSl)
result = "Upload Success:\n"
date = time.strftime("%Y%m%d%H%M%S", time.localtime())
for image in images:
file_type = os.path.splitext(image)[-1]
new_file_name = date + file_type
if image.endswith(".png") or image.endswith(".jpg") or image.endswith(".gif"):
content_type ="image/"+file_type.replace(".", "");
else:
content_type ="image/jpg"
continue
try:
minioClient.fput_object(bucket_name=bucket, object_name= new_file_name, file_path=image,content_type=content_type)
if image.endswith("temp"):
os.remove(image)
result = result +"http://"+ip+":"+port+ "/"+bucket+"/" + new_file_name + "\n"
except ResponseError as err:
result = result + "error:" + err.message + "\n"
print(result)
3、将文件桶/Bucket 改为读写状态
![image-20220302002716576](https://img-blog.csdnimg.cn/img_convert/54e0f8abd89bdd5e1c35196c6abc95d3.png)
4、设置typora执行脚本
![image-20220302002841207](https://img-blog.csdnimg.cn/img_convert/2302364b0f02b47d1bd921a4313bd796.png)
5、测试
点击验证图片上传选项查看配置是否成功