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

 

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

1. FastDFS的Python客户端

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

安装

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

pip install fdfs_client-py-master.zip
pip install mutagen
pip isntall requests

使用

使用FastDFS客户端,需要有配置文件。我们在meiduo_mall/utils目录下新建fastdfs目录,将提供给大家的client.conf配置文件放到这个目录中。

需要修改一下client.conf配置文件

base_path=FastDFS客户端存放日志文件的目录
tracker_server=运行tracker服务的机器ip:22122

上传文件需要先创建fdfs_client.client.Fdfs_client的对象,并指明配置文件,如

from fdfs_client.client import Fdfs_client
client = Fdfs_client('meiduo_mall/utils/fastdfs/client.conf')

通过创建的客户端对象执行上传文件的方法

client.upload_by_filename(文件名)
或
client.upload_by_buffer(文件bytes数据)

如:

>>> ret = client.upload_by_filename('/Users/delron/Desktop/1.png')
getting connection
<fdfs_client.connection.Connection object at 0x1098d4cc0>
<fdfs_client.fdfs_protol.Tracker_header object at 0x1098d4908>
>>> ret
{'Group name': 'group1', 'Remote file_id': 'group1/M00/00/02/CtM3BVr-k6SACjAIAAJctR1ennA809.png', 'Status': 'Upload successed.', 'Local file name': '/Users/delron/Desktop/1.png', 'Uploaded size': '151.00KB', 'Storage IP': '10.211.55.5'}
>>>
  • Remote file_id 即为FastDFS保存的文件的路径

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值