예제 #1
0
 def delete(self, name):
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return
     name = self._get_valid_name(name)
     cos = CosObject()
     cos.delete_object(name)
예제 #2
0
 def _open(self, name, mode='rb'):
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return ''
     cos = CosObject()
     response = cos.get_object(name, True)
     return response.content
예제 #3
0
 def size(self, name):
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return 0
     name = self._get_valid_name(name)
     cos = CosObject()
     response = cos.head_object(name, True)
     if response.status_code == 200:
         return response.headers['Content-Length']
예제 #4
0
 def _save(self, name, content):
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return name
     name = self._get_valid_name(name)
     name = self._get_available_name(name)
     content = content.read()
     cos_object = CosObject()
     response = cos_object.put_object(name, content)
     return response.request.path_url
예제 #5
0
 def _open(self, name, mode='rb'):
     # Use to open the file
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return ''
     cos = CosObject()
     if name[0] != '/':
         name = '/' + name
     response = cos.get_object(name, True)
     return response.content
예제 #6
0
 def size(self, name):
     # Returns the total size, in bytes, of the file referenced by name.
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return 0
     name = self._get_valid_name(name)
     cos = CosObject()
     response = cos.head_object(name, True)
     if response.status_code == 200:
         return response.headers['Content-Length']
예제 #7
0
 def exists(self, name):
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return True
     name = self._get_valid_name(name)
     cos = CosObject()
     response = cos.head_object(name, True)
     if response.status_code == 200:
         return True
     else:
         return False
예제 #8
0
 def exists(self, name):
     # Returns True if a file referenced by the given name already exists in the storage system,
     # or False if the name is available for a new file.
     if name.startswith('http'):
         # 直接存的URL,直接返回,这类数据不支持取content
         return True
     name = self._get_valid_name(name)
     cos = CosObject()
     response = cos.head_object(name, True)
     if response.status_code == 200:
         return True
     else:
         return False
예제 #9
0
    def _save(self, name, content, max_length=None):
        # Called by Storage.save().
        # The name will already have gone through get_valid_name() and get_available_name(),
        # and the content will be a File object itself
        # Should return the actual name of name of the file saved

        if name.startswith('http'):
            # 直接存的URL,直接返回,这类数据不支持取content
            return name
        name = self._get_valid_name(name)
        name = self._get_available_name(name, max_length=max_length)
        content = content.read()
        cos_object = CosObject()
        response = cos_object.put_object(name, content)
        return response.request.path_url