【愚公系列】2022年01月 Django商城项目 21-FastDFS文件上传下载流程实操
【摘要】 前言 一、图片上传和下载流程 二、FastDFS容器部署 1.解压容器sudo docker load -i fastdfs_docker.tar 2.启动tracker serverdocker run -dit --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs delron/fastdfs tracker 3.启动...
前言
一、图片上传和下载流程
二、FastDFS容器部署
1.解压容器
sudo docker load -i fastdfs_docker.tar
2.启动tracker server
docker run -dit --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs delron/fastdfs tracker
3.启动storage server
docker run -dit --network=host --name storage -e TRACKER_SERVER=172.22.186.81:22122 -v /var/fdfs/storage:/var/fdfs delron/fastdfs storage
4.服务启动后
三、Django中添加配置文件
1.安装FastDFS包
注意:winodws下直接安装fdfs_client-py-master.zip 会报错
pip install mutagen
pip install requests
pip install fdfs_client-py-master.zip
2.client.conf
# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=120
# the base path to store log files
base_path=/home/python/Desktop/
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=172.22.186.81:22122
#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info
# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false
# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600
# if load FastDFS parameters from tracker server
# since V4.05
# default value is false
load_fdfs_parameters_from_tracker=false
# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V4.05
use_storage_id = false
# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V4.05
storage_ids_filename = storage_ids.conf
#HTTP settings
http.tracker_server_port=80
#use "#include" directive to include HTTP other settiongs
##include http.conf
3.业务端源码
from fdfs_client.client import Fdfs_client
#2.创建客户端实例,加载指定配置文件
client = Fdfs_client('utils/fdfs/client.conf')
#3.上传图片
# filename 写绝对路径
client.upload_by_filename('/home/python/Desktop/images/mei.png')
client.upload_by_filename('long.png')
4.查看图片
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)