minio搭建图床 配合typora实现写博客图片自动上传

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 改为读写状态

minio搭建图床 配合typora实现写博客图片自动上传_第1张图片

4、设置typora执行脚本

minio搭建图床 配合typora实现写博客图片自动上传_第2张图片

5、测试

点击验证图片上传选项查看配置是否成功

你可能感兴趣的:(学习,java,docker)