Exemplo n.º 1
0
    def copy(self, bucket, key, bucket_to, key_to, callback=None):
        """复制文件:

        将指定资源复制为新命名资源,具体规格参考:
        http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html

        Args:
            bucket:     待操作资源所在空间
            bucket_to:  目标资源空间名
            key:        待操作资源文件名
            key_to:     目标资源文件名

        Returns:
            一个dict变量,成功返回NULL,失败返回{"error": "<errMsg string>"}
            一个ReponseInfo对象
        """
        resource = entry(bucket, key)
        to = entry(bucket_to, key_to)
        self.__rs_do('copy', callback, resource, to)
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    def delete(self, bucket, key, callback=None):
        """删除文件:

        删除指定资源,具体规格参考:
        http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html

        Args:
            bucket: 待获取信息资源所在的空间
            key:    待获取资源的文件名

        Returns:
            一个dict变量,成功返回NULL,失败返回{"error": "<errMsg string>"}
            一个ReponseInfo对象
        """
        resource = entry(bucket, key)
        self.__rs_do('delete', callback, resource)
Exemplo n.º 4
0
    def prefetch(self, bucket, key, callback=None):
        """镜像回源预取文件:

        从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源,具体规格参考
        http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html

        Args:
            bucket: 待获取资源所在的空间
            key:    代获取资源文件名

        Returns:
            一个dict变量,成功返回NULL,失败返回{"error": "<errMsg string>"}
            一个ReponseInfo对象
        """
        resource = entry(bucket, key)
        self.__io_do('prefetch', callback, resource)
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    def stat(self, bucket, key, callback=None):
        """获取文件信息:

        获取资源的元信息,但不返回文件内容,具体规格参考:
        http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html

        Args:
            bucket: 待获取信息资源所在的空间
            key:    待获取资源的文件名

        Returns:
            一个dict变量,类似:
                {
                    "fsize":        5122935,
                    "hash":         "ljfockr0lOil_bZfyaI2ZY78HWoH",
                    "mimeType":     "application/octet-stream",
                    "putTime":      13603956734587420
                }
            一个ReponseInfo对象
        """
        resource = entry(bucket, key)
        self.__rs_do('stat', callback, resource)
Exemplo n.º 7
0
def _two_key_batch(operation, source_bucket, key_pairs, target_bucket):
    if target_bucket is None:
        target_bucket = source_bucket
    return [_build_op(operation, entry(source_bucket, k), entry(target_bucket, v)) for k, v in key_pairs.items()]
Exemplo n.º 8
0
def _one_key_batch(operation, bucket, keys):
    return [_build_op(operation, entry(bucket, key)) for key in keys]
Exemplo n.º 9
0
def op_save(op, bucket, key):
    return pipe_cmd(op, 'saveas/' + entry(bucket, key))