minio搭建图床 配合typora实现写博客图片自动上传
1、搭建minio
查看博客:/#/info?blogOid=32
2、使用脚本(python)
使用之前需要添加依赖,分别需要添加miniorequests依赖
pip install minio# 也可以百度自己查看如何安装 (因为博主不是python的所有可能会存在失误)pip install requests
ps:博主是使用 pycharm 自动安装的依赖
2.1、脚本
import osimport timeimport uuidimport sysimport requestsfrom minio import Miniofrom minio.error import ResponseErrorimport warningsip = ""port = ""accessKey = ""secretKey = ""isSSl = Falsebucket = ""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_typeif image.endswith(".png") or image.endswith(".jpg") or image.endswith(".gif"):content_type ="image/"+file_type.replace(".", "");else:content_type ="image/jpg"continuetry: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 改为读写状态
4、设置typora执行脚本
5、测试
点击验证图片上传选项查看配置是否成功