fastdfs python客户端fdfs_client_py使用问题

刚刚在使用fdfs分布式存储的python客户端上传从文件时,出现下面这个问题

使用环境为:python版本:python 2.6.6

                        fdfs 版本:5.05

                       服务器操作系统:centos

                       fdfs_client_py版本:1.2.6

                       fdfs_client_py版本的github地址为:https://github.com/hay86/fdfs_client-py

上传文件时出现如下问题:

             raise DataError('[-] Error:%d,s'%(th.status,os.strerror(th.status)))

              DataEoor:[-] Error:2,No such file or directory


根据提示,可以知道是从文件上传失败,说没有这个文件或目录,但是明明我的本地有这个从文件。

我将 python版本换成2.7.3也没用

将fdfs_client_py换成最新版也还是没用

但是我直接使用它的源码下的测试程序却上传主文件和从文件都没问题,如下所示:


难道是我的上传代码写的有问题,我是这样写的:

    def upload_file(self,filePath=None,slaveFilePath=None): 
        #upload the apk and the apk details html file into fastdfs storage
        #apk file as master file while html file as slave file
        if filePath is None:
            return None
        ret={}
        client=Fdfs_client(self.m_clientConf)
        result=client.upload_by_filename(filePath) #upload master file
        master_fileId=''
        if result is not None: #success
            self.m_logger.info(" save %s into fdfs success"%filePath) 
            print " save %s into fdfs success"%filePath
            print result
            ret['storageIp']=result['Storage IP']
            ret['groupName']=result['Group name']
            ret['masterFileId']=result['Remote file_id']
            master_fileId=result['Remote file_id']
        print slaveFilePath,master_fileId
        if(slaveFilePath is not None): #upload slave file
            slave_res=client.upload_slave_by_filename(slaveFilePath,master_fileId,'-html')
            if slave_res is not None: #success
                self.m_logger.info(" save slave %s into fdfs success"%slaveFilePath) 
                ret['slaveFileId']=slave_res['Remote file_id']
        return ret #return the storage info

但是当我改为如下,即直接指定主文件id ,又可以上传从文件了,当然这个主文件id必须存在

def upload_file(filePath=None,slaveFilePath=None): 
    #upload the apk and the apk details html file into fastdfs storage
    #apk file as master file while html file as slave file
    if filePath is None:
        return None
    
    ret={}
    client=Fdfs_client('client.conf')
    '''
    result=client.upload_by_filename(filePath) #upload master file
    master_fileId=''
    if result is not None: #success
        ret['storageIp']=result['Storage IP']
        ret['groupName']=result['Group name']
        ret['masterFileId']=result['Remote file_id']
        master_fileId=result['Remote file_id']
    print 'ret',ret
    '''
    if(slaveFilePath is not None): #upload slave file
        file_prefix='-html'
        slave_res=client.upload_slave_by_filename(slaveFilePath,"group1/M00/00/00/wKgLNFZMJQqAMZd1AAAFDeT7vec1033.py",file_prefix)
        if slave_res is not None: #success
            ret['slaveFileId']=slave_res['Remote file_id']
    return ret #return the storage info

这是什么情况,难道我上传主文件时返回的主文件id是错的吗?

于是我把服务器上的python重装成2.7,3的,结果再导入这个fdfs_client的包时提示:

ImportError: No module named sendfile

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

上面的问题还没有解决,等解决了再更新


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
fdfs_upload_file是一个基于FastDFS开源分布式文件系统的函数或方法,用于上传文件到FastDFS服务器上。 FastDFS是一种高性能、轻量级的分布式文件系统,主要用于分布式存储大文件。fdfs_upload_file函数就是使用FastDFS提供的接口,通过网络连接将文件上传到FastDFS服务器上。 具体的使用方法可以通过以下步骤实现: 1. 首先,需要在代码中创建一个FastDFS客户端对象,用于连接FastDFS服务器。 2. 然后,通过调用fdfs_upload_file函数,传入要上传的文件路径和文件名作为参数,将文件从本地上传到FastDFS服务器上。 3. 在上传之前,需要确保FastDFS服务器已经正确配置和部署,并且已经连接到网络。 4. 在文件上传完成后,fdfs_upload_file函数会返回一个文件ID或URL,用于后续的文件访问或下载。 fdfs_upload_file函数的使用需要注意以下几点: 1. 必要的错误处理,包括网络连接错误、文件上传失败等情况。 2. 对上传的文件进行合法性检查,如文件大小、文件类型等限制。 3. 对于大文件的上传,可以通过分块上传的方式实现,并且可以实时显示上传进度。 4. 在多线程环境下,需要考虑数据的一致性和并发上传的处理方式。 总之,fdfs_upload_file是一个用于将文件上传到FastDFS服务器的函数,通过调用该函数可以方便地实现文件的分布式存储和访问。使用该函数需要通过FastDFS客户端对象进行连接和操作,并且需要对上传的文件进行合法性检查和错误处理。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zlp1992

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值