---
# System prepended metadata

title: (TOC)透過 flask 中的 send_file 拿到fsm狀態圖

---

# (TOC)透過 flask 中的 send_file 拿到fsm狀態圖

### 需求
> 靠北我只有mac可以安裝pygraphviz
1. 需安裝 pygraphviz,request
2. 連上server(heroku or ngrok)
3. pipenv等相關套件安裝

### 程式畫面
 ![](https://i.imgur.com/Iu9qdJg.jpg)
### 步驟
1. 建立get_file.py，並打入程式碼
```python=
import requests

SERVER_IP = "0.0.0.0" #IP
API_SERVER = "http://" + SERVER_IP + ":8000" #port
DOWNLOAD_IMAGE_API = "/show-fsm"

try:
    downloadImageInfoResponse = requests.get(
        API_SERVER + DOWNLOAD_IMAGE_API)

    if downloadImageInfoResponse.status_code == 200:
        with open('img.jpg', 'wb') as getFile:
            getFile.write(downloadImageInfoResponse.content)
except Exception as err:
    print('Other error occurred %s' % {err})
```
2. 在終端機輸入 pipenv run app.py
3. 打開另一個終端機輸入pipenv run get_file.py
4. 即可拿到生成的fsm圖
### reference
[【 Python 】透過 flask 中的 send_file 傳送影像](https://learningsky.io/python-flask-restful-api-send-file/?fbclid=IwAR1RP8XiT7s36EFc6Om8ywN2ijIBukboBHQof_8z2DmPJ8YQNhASRT3lvmg)