python3与fastdfs分布式文件系统交互

joynet00 2020-06-21

一、先配置好自己的分布式文件系统,参考另一篇文章:

https://www.cnblogs.com/vevian/p/13170228.html

二、安装第三方库py3Fdfs

pip install py3Fdfs

三、实际应用,参考文档

https://pypi.org/project/py3Fdfs/

from fdfs_client.client import get_tracker_conf, Fdfs_client

# client.conf配置文件路径
conf = get_tracker_conf(r‘client.conf‘)
client = Fdfs_client(conf)
# 文件路径
result = client.upload_appender_by_filename(r‘U01.png‘)
print(result)

注意:client.conf是从fdfs服务器上复制到django代码机器上的文件,需要将里面的base_path路径修改成存放client.conf的路径

四、执行结果

{‘Group name‘: b‘group1‘, ‘Remote file_id‘: b‘group1/M00/00/00/wKg0hV7vNJCEBJ0PAAAAALU5g1M201.png‘, ‘Status‘: ‘Upload successed.‘, ‘Local file name‘: ‘E:\\photo\\IU01.png‘, ‘Uploaded size‘: ‘336.09KB‘, ‘Storage IP‘: b‘192.168.52.133‘}

Process finished with exit code 0

相关推荐