一.  介绍
    本章主要讲述的是通过Typora + Python 脚本来实现Typora 工具编辑Markdown文件时的图片上传处理。通过Docker部署Nginx,MinIO容器,Nginx代理访问MinIO资源。
效果如下:

二. 相关脚本
    以下是相关服务及脚本实例。
1. Python3
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
   | 
 
 
 
 
 
 
 
 
 
  import sys import uuid from pathlib import Path from minio import Minio
 
 
  minio_storage = Minio("192.168.30.180:9000", access_key='admin', secret_key='YouGuess', secure=False) images = sys.argv[1:] for image in images:     print("File Uploading ...")     suffix = Path(image).suffix     file_name = str(uuid.uuid4()) + suffix          bucket_name = "hexo-blog"     if not minio_storage.bucket_exists(bucket_name):                  minio_storage.make_bucket(bucket_name)     minio_storage.fput_object(bucket_name, file_name, image, content_type="image/png", part_size=10485760)     print("https://www.lmaye.com/files/{}/{}".format(bucket_name, file_name))
 
  | 
 
2. Nginx 配置
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
   |  worker_processes  1;
 
 
 
 
 
 
  events { worker_connections  1024; }
  http { include       mime.types; default_type  application/octet-stream;
 
 
 
 
 
 
  sendfile        on;
 
 
  keepalive_timeout  65;
 
 
  server { listen       80; server_name  localhost;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  error_page   500 502 503 504  /50x.html; location = /50x.html { root   html; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  location ^~ /files/ { root /usr/share/nginx/html; } } }
 
  | 
 
3. Docker Compose
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
   | version: "3" services:   nginx:     container_name: blog-nginx     image: nginx:1.16     restart: on-failure     ports:       - 80:80       - 443:443     volumes:       - ./nginx/www:/usr/share/nginx/html       - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf       - ./nginx/logs:/var/log/nginx
    minio:          container_name: blog-minio          image: minio/minio:latest                         restart: on-failure     command: server /data          ports:       - 9000:9000     environment:       MINIO_ACCESS_KEY: admin       MINIO_SECRET_KEY: YouGuess          volumes:              - ./nginx/www/files:/data       - ./minio/conf:/root/.minio
   | 
 
三. Typora配置
1. Python脚本测试:
    CMD命令:
1 2 3
   | E:\md>python oss_upload.py "C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210121112644841.png" File Uploading ... https://www.lmaye.com/files/hexo-blog/7dd6ea8a-551c-48dc-baba-e3506e52556a.gif
   | 
 
2. Typora工具配置
    配置步骤:文件 -> 偏好设置 -> 图像
    如下所示
    命令:python oss_upload.py(Python脚本没有写觉得路径,因为我把脚本放在了MD文件目录下)
