Pārlūkot izejas kodu

fastapi+minio——finally

clxHardstudy 1 gadu atpakaļ
vecāks
revīzija
6ee4811191
4 mainītis faili ar 183 papildinājumiem un 16 dzēšanām
  1. 9 16
      Dockerfile
  2. 62 0
      README.md
  3. 101 0
      Return.md
  4. 11 0
      docker-compose.yml

+ 9 - 16
Dockerfile

@@ -1,22 +1,15 @@
-#FROM python:3.10
-#
-#WORKDIR ./peoject
-#
-#COPY ./requirements.txt /app/requirement.txt
-#
-#
-#RUN set -eux \
-#    && pip install --upgrade pip \
-#    && pip install -r ./requirements.txt
-#
-#COPY . /project1
 FROM python:3.10
 
-WORKDIR /app
+WORKDIR /src
 
-COPY ./requirements.txt .
+COPY ./requirements.txt ./src/requirements.txt
 
+RUN set -eux \
+    && apk add --no-cache --virtual .build-deps build-base \
+    libressl-dev libffi-dev gcc musl-dev python3-dev \
+    postgresql-dev \
+    && pip install --upgrade pip setuptools wheel \
+    && pip install -r /src/requirements.txt \
 
-RUN pip install -r requirements.txt
 
-COPY . .
+COPY . /src/

+ 62 - 0
README.md

@@ -0,0 +1,62 @@
+A simple example of using Fast API in Python.
+
+## Preconditions:
+
+- Python 3
+
+## Clone the project
+
+```
+git clone https://github.com/marciovrl/fastapi-example.git
+```
+
+## Run local
+
+### Install dependencies
+
+```
+pip install -r requirements.txt
+```
+
+### Run minio
+```
+docker run -p 9000:9000 minio/minio:RELEASE.2021-06-17T00-10-46Z server /data
+```
+
+### Run server
+
+```
+uvicorn app.main:app --reload
+```
+
+### Run test
+
+```
+pytest test/test.py
+```
+
+## Run with docker
+
+### Run server
+
+```
+docker-compose up -d --build
+```
+
+### Run test
+
+```
+docker-compose exec app pytest test/test.py
+```
+
+## API documentation (provided by Swagger UI)
+
+```
+http://127.0.0.1:8000/docs
+```
+
+### Run server
+
+```
+docker-compose exec --username=fastapi 
+```

+ 101 - 0
Return.md

@@ -0,0 +1,101 @@
+#### 项目目标
+
+- 使用fastapi + minio实现图床功能, 上传+下载 + 删除
+
+
+
+该项目由三个接口组成
+
+- 上传接口
+- 下载接口
+- 删除接口
+
+
+
+###### 上传接口:
+
+- URI设计 :/file
+
+- 访问地址:localhost:8000/file
+
+- 传参:文件【file】
+  传入一个二进制文件流
+
+- 返回值:状态码+URI
+
+  样例:
+
+  ```python
+  -- 操作成功
+  {
+      "status": 200,
+      "data": "1685503168185763.png",
+      "msg":""
+  }
+  
+  -- 操作失败
+  {
+      "status": 400,
+      "data":""
+      "msg": "上传失败"
+  }
+  ```
+
+
+
+
+
+###### 下载接口:
+
+- RUI设计:/file/{uid}
+
+- 访问地址:localhost:8000/file
+
+- 传参:uid:uid是图片名称信息
+
+- 返回值:
+
+  图片预览或是下载
+
+- 效果展示:
+
+  预览:
+
+  ![image-20230531113201203](C:\Users\86178\AppData\Roaming\Typora\typora-user-images\image-20230531113201203.png)
+
+
+
+
+
+###### 删除接口:
+
+- RUI设计:/file/{uid}
+
+- 访问地址:localhost:8000/file/{uid}
+
+- 传参:uid:uid是图片名称信息
+
+- 返回值:
+
+  样例:
+
+  ```python
+  -- 操作成功
+  {
+      "data":[]
+      "msg": "",
+      "status": 200
+  }
+  
+  -- 操作失败
+  {
+      "data":[]
+      "msg": "Not Found",
+      "status": 404
+  }
+  ```
+  
+  
+
+
+

+ 11 - 0
docker-compose.yml

@@ -0,0 +1,11 @@
+version: "3.10"
+
+services:
+  app:
+    build: .
+    container_name: app
+    command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8000
+    volumes:
+      - ./:/src/
+    ports:
+      - 8000:8000