Python3 and FastDFS interaction (py3Fdfs)

FastDFS existing databases and interactive python, mostly by downloading fdfs-client-py, pip local installation.
However, the module is only applicable to Python2, and adaptation FastDFS version is more ancient.

In Python3, there are corresponding py3fdfs module

installation

pip install py3Fdfs

 

. py3fdfs from fdfs-client, but in the course, and the old version is slightly different (py3fdfs net example Officer wrong)

to create a client instance when the object can not be passed directly address string configuration file, otherwise an error.
Error code: TypeError : type object argument after ** must be

a mapping, not str by the module get_tracker_conf . after the function, obtaining the configuration file incoming

Example:

from fdfs_client.client import Fdfs_client, get_tracker_conf

tracker_path = get_tracker_conf('/etc/fdfs/client.conf')

client = Fdfs_client(tracker_path)

ret = client.upload_by_filename('./test')

print(ret)

 


! # Upload the dictionary returns after successful, where 'Remote file_id' corresponding to the key value by the legacy module string type to type byte.
Is, the returned document id is a byte

if custom upload projects, the required conversion to return id is a string file or the server error.
error Code: a-like Object bytes required iS, Not 'STR'

Example:

class FastDFSStorage(Storage):
'''自定义上传类'''
    ...   

    def _save(self, name, content):
        '''_save方法'''

        conf_path = get_tracker_conf('./utils/fdfs/client.conf')
        client = Fdfs_client(conf_path)
        result = client.upload_by_buffer(content.read())

        if result.get('Status') != 'Upload successed.':
            raise Exception(')'Upload file failed to FastDFS

        filename = result.get('Remote file_id')

        # return filename
        return str(filename)

 

Guess you like

Origin www.cnblogs.com/jrri/p/11570089.html