up2minio


Nameup2minio JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://www.dfql.io
Summary将图片上传至 Minio 的扩展模块
upload_time2024-12-14 04:20:45
maintainerNone
docs_urlNone
authordaofengqianlin
requires_python>=3.6
licenseApache 2.0
keywords sapic minio storage hook
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            up2minio - Sapic 图床的 Minio 存储钩子扩展
==============================================

**许可证**: 本项目基于 `Apache 2.0 许可证 <https://www.apache.org/licenses/LICENSE-2.0>`_ 开源,您可以自由使用、修改和分发本项目,但需保留原始版权声明及许可证信息。

---

简介
----

``up2minio`` 是基于 `Sapic <https://github.com/daofengqianlin/Sapic>`_ 的一个扩展模块,用于将上传的图片保存到自建的 ``Minio`` 对象存储中。它支持通过 Minio 的 S3 兼容 API 上传图片,并提供必要的配置与管理功能。

---

安装
----

正式 ‖ 开发版本
^^^^^^^^^^^^^^^^

开发版本安装
`````````````
运行以下命令安装开发版本:

.. code-block:: bash

    pip install -U git+https://github.com/Daofengql/Sapicbed-Minio-Hook.git@main

---

开始使用
--------

环境准备
^^^^^^^^^

1. 部署并运行 `Sapic 图床 <https://github.com/daofengqianlin/Sapic>`_。
2. 确保 Minio 服务已搭建并配置了所需的存储桶(Bucket)。

添加扩展
^^^^^^^^^

1. 登录 Sapic 站点管理员后台。
2. 进入 **站点管理 > 钩子扩展** 页面。
3. 添加钩子扩展:
   - **模块名称**:输入 ``up2minio``。
   - 提交保存后,模块会被加载(请确保扩展模块已通过 pip 安装到服务器)。

配置扩展
^^^^^^^^^

1. 进入 **站点管理 > 网站设置** 页面。
2. 在页面底部的钩子配置区域,填写 Minio 的相关信息:
   - **Bucket**:Minio 存储桶名称(需公开可读)。
   - **Region**:Minio 服务端的节点名称。
   - **AccessKey**:对存储桶有权限的 Access Key。
   - **SecretKey**:对存储桶有权限的 Secret Key。
   - **Endpoint**:Minio 服务的 S3 API 地址(如 ``127.0.0.1:9000``,无需包含协议头)。
   - **CDN Domain**:自定义 CDN 加速域名,需包含协议头,例如 ``https://cdn.example.com``。
   - **存储根目录**:图片存储在存储桶内的路径(非存储桶名称)。

启用存储后端
^^^^^^^^^^^^^

1. 在 **站点管理 > 网站设置 > 上传区域** 页面。
2. 设置存储后端为 ``up2minio``。
3. 保存设置后,所有上传的图片将存储到 Minio。

---

功能特点
--------

1. **扩展性**:基于 Sapic 的钩子架构,可无缝集成。
2. **支持自定义 CDN**:通过配置 CDN 域名优化访问速度。
3. **存储路径灵活**:支持自定义 Minio 存储根目录。
4. **安全性**:通过 AK/SK 验证访问,确保数据安全。

---

API 方法
--------

``get_bucket_obj()``
^^^^^^^^^^^^^^^^^^^^
返回 Minio 客户端对象。

- **用途**:初始化 Minio 客户端。

``upimg_save(**kwargs)``
^^^^^^^^^^^^^^^^^^^^^^^^
上传图片到 Minio。

- **参数**:
  - ``filename``:图片文件名。
  - ``stream``:图片文件流。
  - ``upload_path``:上传路径。
- **返回**:字典,包含上传结果(``src`` 为图片的完整 URL)。

``upimg_delete(sha, upload_path, filename, basedir, save_result)``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

删除存储在 Minio 中的图片。

- **参数**:
  - ``sha``:图片的哈希值。
  - ``upload_path``:上传路径。
  - ``filename``:图片文件名。
  - ``basedir``:存储根目录。
  - ``save_result``:保存时的结果。
- **返回**:无。

---

注意事项
--------

1. **HTTPS 限制**:目前仅支持 HTTPS,若 Minio 不支持 HTTPS,请使用 Nginx 配置反向代理解决。
2. **存储桶权限**:存储桶需设置为公开可读,以便图片能被外部访问。
3. **路径配置**:
   - **Bucket** 和 **存储根目录** 配置正确,否则会导致文件存储失败。
4. **CDN 配置**:若未配置 CDN 域名,将直接使用 Minio Endpoint 地址。

---

示例配置
--------

- **Bucket**: ``my-images``
- **Region**: ``us-east-1``
- **AccessKey**: ``your-access-key``
- **SecretKey**: ``your-secret-key``
- **Endpoint**: ``minio.example.com:9000``
- **CDN Domain**: ``https://cdn.example.com``
- **存储根目录**: ``uploads/images``

---

许可证
------

本项目基于 `Apache 2.0 许可证 <https://www.apache.org/licenses/LICENSE-2.0>`_ 发布,用户可自由使用、修改和分发,但需保留原始版权声明及许可证信息。

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.dfql.io",
    "name": "up2minio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "sapic minio storage hook",
    "author": "daofengqianlin",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/d0/1b/fb815c52783e2b3a01a04a8d0d65698161c3c84a4f32bd3352605730b768/up2minio-0.0.2.tar.gz",
    "platform": null,
    "description": "up2minio - Sapic \u56fe\u5e8a\u7684 Minio \u5b58\u50a8\u94a9\u5b50\u6269\u5c55\n==============================================\n\n**\u8bb8\u53ef\u8bc1**: \u672c\u9879\u76ee\u57fa\u4e8e `Apache 2.0 \u8bb8\u53ef\u8bc1 <https://www.apache.org/licenses/LICENSE-2.0>`_ \u5f00\u6e90\uff0c\u60a8\u53ef\u4ee5\u81ea\u7531\u4f7f\u7528\u3001\u4fee\u6539\u548c\u5206\u53d1\u672c\u9879\u76ee\uff0c\u4f46\u9700\u4fdd\u7559\u539f\u59cb\u7248\u6743\u58f0\u660e\u53ca\u8bb8\u53ef\u8bc1\u4fe1\u606f\u3002\n\n---\n\n\u7b80\u4ecb\n----\n\n``up2minio`` \u662f\u57fa\u4e8e `Sapic <https://github.com/daofengqianlin/Sapic>`_ \u7684\u4e00\u4e2a\u6269\u5c55\u6a21\u5757\uff0c\u7528\u4e8e\u5c06\u4e0a\u4f20\u7684\u56fe\u7247\u4fdd\u5b58\u5230\u81ea\u5efa\u7684 ``Minio`` \u5bf9\u8c61\u5b58\u50a8\u4e2d\u3002\u5b83\u652f\u6301\u901a\u8fc7 Minio \u7684 S3 \u517c\u5bb9 API \u4e0a\u4f20\u56fe\u7247\uff0c\u5e76\u63d0\u4f9b\u5fc5\u8981\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u529f\u80fd\u3002\n\n---\n\n\u5b89\u88c5\n----\n\n\u6b63\u5f0f \u2016 \u5f00\u53d1\u7248\u672c\n^^^^^^^^^^^^^^^^\n\n\u5f00\u53d1\u7248\u672c\u5b89\u88c5\n`````````````\n\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5f00\u53d1\u7248\u672c\uff1a\n\n.. code-block:: bash\n\n    pip install -U git+https://github.com/Daofengql/Sapicbed-Minio-Hook.git@main\n\n---\n\n\u5f00\u59cb\u4f7f\u7528\n--------\n\n\u73af\u5883\u51c6\u5907\n^^^^^^^^^\n\n1. \u90e8\u7f72\u5e76\u8fd0\u884c `Sapic \u56fe\u5e8a <https://github.com/daofengqianlin/Sapic>`_\u3002\n2. \u786e\u4fdd Minio \u670d\u52a1\u5df2\u642d\u5efa\u5e76\u914d\u7f6e\u4e86\u6240\u9700\u7684\u5b58\u50a8\u6876\uff08Bucket\uff09\u3002\n\n\u6dfb\u52a0\u6269\u5c55\n^^^^^^^^^\n\n1. \u767b\u5f55 Sapic \u7ad9\u70b9\u7ba1\u7406\u5458\u540e\u53f0\u3002\n2. \u8fdb\u5165 **\u7ad9\u70b9\u7ba1\u7406 > \u94a9\u5b50\u6269\u5c55** \u9875\u9762\u3002\n3. \u6dfb\u52a0\u94a9\u5b50\u6269\u5c55\uff1a\n   - **\u6a21\u5757\u540d\u79f0**\uff1a\u8f93\u5165 ``up2minio``\u3002\n   - \u63d0\u4ea4\u4fdd\u5b58\u540e\uff0c\u6a21\u5757\u4f1a\u88ab\u52a0\u8f7d\uff08\u8bf7\u786e\u4fdd\u6269\u5c55\u6a21\u5757\u5df2\u901a\u8fc7 pip \u5b89\u88c5\u5230\u670d\u52a1\u5668\uff09\u3002\n\n\u914d\u7f6e\u6269\u5c55\n^^^^^^^^^\n\n1. \u8fdb\u5165 **\u7ad9\u70b9\u7ba1\u7406 > \u7f51\u7ad9\u8bbe\u7f6e** \u9875\u9762\u3002\n2. \u5728\u9875\u9762\u5e95\u90e8\u7684\u94a9\u5b50\u914d\u7f6e\u533a\u57df\uff0c\u586b\u5199 Minio \u7684\u76f8\u5173\u4fe1\u606f\uff1a\n   - **Bucket**\uff1aMinio \u5b58\u50a8\u6876\u540d\u79f0\uff08\u9700\u516c\u5f00\u53ef\u8bfb\uff09\u3002\n   - **Region**\uff1aMinio \u670d\u52a1\u7aef\u7684\u8282\u70b9\u540d\u79f0\u3002\n   - **AccessKey**\uff1a\u5bf9\u5b58\u50a8\u6876\u6709\u6743\u9650\u7684 Access Key\u3002\n   - **SecretKey**\uff1a\u5bf9\u5b58\u50a8\u6876\u6709\u6743\u9650\u7684 Secret Key\u3002\n   - **Endpoint**\uff1aMinio \u670d\u52a1\u7684 S3 API \u5730\u5740\uff08\u5982 ``127.0.0.1:9000``\uff0c\u65e0\u9700\u5305\u542b\u534f\u8bae\u5934\uff09\u3002\n   - **CDN Domain**\uff1a\u81ea\u5b9a\u4e49 CDN \u52a0\u901f\u57df\u540d\uff0c\u9700\u5305\u542b\u534f\u8bae\u5934\uff0c\u4f8b\u5982 ``https://cdn.example.com``\u3002\n   - **\u5b58\u50a8\u6839\u76ee\u5f55**\uff1a\u56fe\u7247\u5b58\u50a8\u5728\u5b58\u50a8\u6876\u5185\u7684\u8def\u5f84\uff08\u975e\u5b58\u50a8\u6876\u540d\u79f0\uff09\u3002\n\n\u542f\u7528\u5b58\u50a8\u540e\u7aef\n^^^^^^^^^^^^^\n\n1. \u5728 **\u7ad9\u70b9\u7ba1\u7406 > \u7f51\u7ad9\u8bbe\u7f6e > \u4e0a\u4f20\u533a\u57df** \u9875\u9762\u3002\n2. \u8bbe\u7f6e\u5b58\u50a8\u540e\u7aef\u4e3a ``up2minio``\u3002\n3. \u4fdd\u5b58\u8bbe\u7f6e\u540e\uff0c\u6240\u6709\u4e0a\u4f20\u7684\u56fe\u7247\u5c06\u5b58\u50a8\u5230 Minio\u3002\n\n---\n\n\u529f\u80fd\u7279\u70b9\n--------\n\n1. **\u6269\u5c55\u6027**\uff1a\u57fa\u4e8e Sapic \u7684\u94a9\u5b50\u67b6\u6784\uff0c\u53ef\u65e0\u7f1d\u96c6\u6210\u3002\n2. **\u652f\u6301\u81ea\u5b9a\u4e49 CDN**\uff1a\u901a\u8fc7\u914d\u7f6e CDN \u57df\u540d\u4f18\u5316\u8bbf\u95ee\u901f\u5ea6\u3002\n3. **\u5b58\u50a8\u8def\u5f84\u7075\u6d3b**\uff1a\u652f\u6301\u81ea\u5b9a\u4e49 Minio \u5b58\u50a8\u6839\u76ee\u5f55\u3002\n4. **\u5b89\u5168\u6027**\uff1a\u901a\u8fc7 AK/SK \u9a8c\u8bc1\u8bbf\u95ee\uff0c\u786e\u4fdd\u6570\u636e\u5b89\u5168\u3002\n\n---\n\nAPI \u65b9\u6cd5\n--------\n\n``get_bucket_obj()``\n^^^^^^^^^^^^^^^^^^^^\n\u8fd4\u56de Minio \u5ba2\u6237\u7aef\u5bf9\u8c61\u3002\n\n- **\u7528\u9014**\uff1a\u521d\u59cb\u5316 Minio \u5ba2\u6237\u7aef\u3002\n\n``upimg_save(**kwargs)``\n^^^^^^^^^^^^^^^^^^^^^^^^\n\u4e0a\u4f20\u56fe\u7247\u5230 Minio\u3002\n\n- **\u53c2\u6570**\uff1a\n  - ``filename``\uff1a\u56fe\u7247\u6587\u4ef6\u540d\u3002\n  - ``stream``\uff1a\u56fe\u7247\u6587\u4ef6\u6d41\u3002\n  - ``upload_path``\uff1a\u4e0a\u4f20\u8def\u5f84\u3002\n- **\u8fd4\u56de**\uff1a\u5b57\u5178\uff0c\u5305\u542b\u4e0a\u4f20\u7ed3\u679c\uff08``src`` \u4e3a\u56fe\u7247\u7684\u5b8c\u6574 URL\uff09\u3002\n\n``upimg_delete(sha, upload_path, filename, basedir, save_result)``\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n\u5220\u9664\u5b58\u50a8\u5728 Minio \u4e2d\u7684\u56fe\u7247\u3002\n\n- **\u53c2\u6570**\uff1a\n  - ``sha``\uff1a\u56fe\u7247\u7684\u54c8\u5e0c\u503c\u3002\n  - ``upload_path``\uff1a\u4e0a\u4f20\u8def\u5f84\u3002\n  - ``filename``\uff1a\u56fe\u7247\u6587\u4ef6\u540d\u3002\n  - ``basedir``\uff1a\u5b58\u50a8\u6839\u76ee\u5f55\u3002\n  - ``save_result``\uff1a\u4fdd\u5b58\u65f6\u7684\u7ed3\u679c\u3002\n- **\u8fd4\u56de**\uff1a\u65e0\u3002\n\n---\n\n\u6ce8\u610f\u4e8b\u9879\n--------\n\n1. **HTTPS \u9650\u5236**\uff1a\u76ee\u524d\u4ec5\u652f\u6301 HTTPS\uff0c\u82e5 Minio \u4e0d\u652f\u6301 HTTPS\uff0c\u8bf7\u4f7f\u7528 Nginx \u914d\u7f6e\u53cd\u5411\u4ee3\u7406\u89e3\u51b3\u3002\n2. **\u5b58\u50a8\u6876\u6743\u9650**\uff1a\u5b58\u50a8\u6876\u9700\u8bbe\u7f6e\u4e3a\u516c\u5f00\u53ef\u8bfb\uff0c\u4ee5\u4fbf\u56fe\u7247\u80fd\u88ab\u5916\u90e8\u8bbf\u95ee\u3002\n3. **\u8def\u5f84\u914d\u7f6e**\uff1a\n   - **Bucket** \u548c **\u5b58\u50a8\u6839\u76ee\u5f55** \u914d\u7f6e\u6b63\u786e\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u6587\u4ef6\u5b58\u50a8\u5931\u8d25\u3002\n4. **CDN \u914d\u7f6e**\uff1a\u82e5\u672a\u914d\u7f6e CDN \u57df\u540d\uff0c\u5c06\u76f4\u63a5\u4f7f\u7528 Minio Endpoint \u5730\u5740\u3002\n\n---\n\n\u793a\u4f8b\u914d\u7f6e\n--------\n\n- **Bucket**: ``my-images``\n- **Region**: ``us-east-1``\n- **AccessKey**: ``your-access-key``\n- **SecretKey**: ``your-secret-key``\n- **Endpoint**: ``minio.example.com:9000``\n- **CDN Domain**: ``https://cdn.example.com``\n- **\u5b58\u50a8\u6839\u76ee\u5f55**: ``uploads/images``\n\n---\n\n\u8bb8\u53ef\u8bc1\n------\n\n\u672c\u9879\u76ee\u57fa\u4e8e `Apache 2.0 \u8bb8\u53ef\u8bc1 <https://www.apache.org/licenses/LICENSE-2.0>`_ \u53d1\u5e03\uff0c\u7528\u6237\u53ef\u81ea\u7531\u4f7f\u7528\u3001\u4fee\u6539\u548c\u5206\u53d1\uff0c\u4f46\u9700\u4fdd\u7559\u539f\u59cb\u7248\u6743\u58f0\u660e\u53ca\u8bb8\u53ef\u8bc1\u4fe1\u606f\u3002\n\n---\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "\u5c06\u56fe\u7247\u4e0a\u4f20\u81f3 Minio \u7684\u6269\u5c55\u6a21\u5757",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://www.dfql.io"
    },
    "split_keywords": [
        "sapic",
        "minio",
        "storage",
        "hook"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbfaa05be0c9f05ca78092751f9810ca52e10fce47e6a12b622aefba33c9ec9d",
                "md5": "0814e7d7dd5ee1d8412806c7b41f0081",
                "sha256": "4567e9b95a0cb1ce1d647df0b42a0cb9dbefb4cf2c757a3bc125e001eecf9acb"
            },
            "downloads": -1,
            "filename": "up2minio-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0814e7d7dd5ee1d8412806c7b41f0081",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9195,
            "upload_time": "2024-12-14T04:20:43",
            "upload_time_iso_8601": "2024-12-14T04:20:43.182669Z",
            "url": "https://files.pythonhosted.org/packages/cb/fa/a05be0c9f05ca78092751f9810ca52e10fce47e6a12b622aefba33c9ec9d/up2minio-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d01bfb815c52783e2b3a01a04a8d0d65698161c3c84a4f32bd3352605730b768",
                "md5": "c2e62b3ca8290b7e18cea07ca15a5564",
                "sha256": "065b710353560a4d9db77d38f10282ad30385ab1c1e1987d50bbaeb273af7921"
            },
            "downloads": -1,
            "filename": "up2minio-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c2e62b3ca8290b7e18cea07ca15a5564",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 9450,
            "upload_time": "2024-12-14T04:20:45",
            "upload_time_iso_8601": "2024-12-14T04:20:45.823118Z",
            "url": "https://files.pythonhosted.org/packages/d0/1b/fb815c52783e2b3a01a04a8d0d65698161c3c84a4f32bd3352605730b768/up2minio-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-14 04:20:45",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "up2minio"
}
        
Elapsed time: 2.50816s