def file_url(self, host): url = ['http://{0}/mkfile/{1}'.format(host, self.size)] if self.mime_type: url.append('mimeType/{0}'.format(urlsafe_base64_encode(self.mime_type))) if self.key is not None: url.append('key/{0}'.format(urlsafe_base64_encode(self.key))) if self.params: for k, v in self.params.items(): url.append('{0}/{1}'.format(k, urlsafe_base64_encode(v))) url = '/'.join(url) return url
def change_mime(self, bucket, key, mime, callback=None): """修改文件mimeType: 主动修改指定资源的文件类型,具体规格参考: http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html Args: bucket: 待操作资源所在空间 key: 待操作资源文件名 mime: 待操作文件目标mimeType """ resource = entry(bucket, key) encode_mime = urlsafe_base64_encode(mime) self.__rs_do('chgm', callback, resource, 'mime/{0}'.format(encode_mime))
def fetch(self, url, bucket, key, callback=None): """抓取文件: 从指定URL抓取资源,并将该资源存储到指定空间中,具体规格参考: http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html Args: url: 指定的URL bucket: 目标资源空间 key: 目标资源文件名 Returns: 一个dict变量,成功返回NULL,失败返回{"error": "<errMsg string>"} 一个ReponseInfo对象 """ resource = urlsafe_base64_encode(url) to = entry(bucket, key) self.__io_do('fetch', callback, resource, 'to/{0}'.format(to))