python--FastDFS客户端与自定义文件存储系统

1. FastDFS的Python客户端

python版本的FastDFS客户端使用说明参考https://github.com/jefforeilly/fdfs_client-py

安装

安装提供给大家的fdfs_client-py-master.zip到虚拟环境中

安装 fdfs_client_py 会有问题!!!
解决

1.解压后的fdfs_client-py-master\fdfs_client 目录下的storage_client.py
屏蔽第12行  # from fdfs_client.sendfile import *
2.解压后的fdfs_client-py-master 目录下的setup.py
屏蔽sdict字典中的   'ext_modules' 
完成以上两步,接着安装 pip install mutagen  和 pip install requests  ,不然会提示缺少此两个包。

最后 python setup.py install ,成功!
pip install fdfs_client-py-master.zip
pip install mutagen
pip isntall requests
pip install py3Fdfs

使用

Linux 必须关闭防火墙

systemctl stop firewalld

使用FastDFS客户端,需要有配置文件。
需要修改一下client.conf配置文件

# connect timeout in seconds
# default value is 30s
connect_timeout=300

# network timeout in seconds
# default value is 30s
network_timeout=300

# the base path to store log files
base_path=/fastdfs/tracker

# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
#tracker_server=10.20.10.191:22122
tracker_server=121.4.241.243: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=8888

#use "#include" directive to include HTTP other settiongs
##include http.conf

上传

from fdfs_client.client import get_tracker_conf, Fdfs_client

tracker_conf = get_tracker_conf('./fastfdfs_client.conf')
client = Fdfs_client(tracker_conf)

# 文件上传
result = client.upload_by_filename('./docker3.png')
print(result)

结果

{'Group name': b'group1', 'Remote file_id': b'group1/M00/00/00/rBEABWHFkAqAREf0AAP5zIOZglY867.png', 'Status': 'Upload successed.', 'Local file name': './docker3.png', 'Uploaded size': '254.45KB', 'Storage IP': b'121.4.241.243'}

去浏览器直接访问

http://121.4.241.243:8888/group1/M00/00/00/rBEABWHFjwSAIPyyAAP5zIOZglY716.png

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值