标签:code ret except remote conf 继承 status url exist
1.继承django的Storage类,重写open,save和exist方法
from django.core.files.storage import Storage from fdfs_client.client import Fdfs_client class FDFSStorage(Storage): def open(self, name, mode=‘rb‘): pass def save(self, name, content, max_length=None): client = Fdfs_client(‘./utils/fdfs/client.conf‘) res = client.upload_by_buffer(content.read()) if res.get(‘Status‘) != ‘Upload seccessed‘: raise Exception(‘上传文件到fdfs服务器失败‘) filename = res.get(‘Remote file_id‘) return filename def exists(self, name): return False
def url(self, name):
return ‘http://192.168.5.135:8888/‘+name
标签:code ret except remote conf 继承 status url exist
原文地址:https://www.cnblogs.com/yangzixiong/p/11703266.html