|
10 | 10 | from .compact import b, s, u, url_parse, quote |
11 | 11 | from .config import BLOCKSIZE |
12 | 12 | from .httprequest import _put_stream, _put_file, _post_file, ResponseInfo, _uploadhit_file, _download_file, \ |
13 | | - _delete_file, _getfilelist, _head_file, _restore_file, _classswitch_file, _copy_file, _rename_file, _listobjects |
| 13 | + _delete_file, _getfilelist, _head_file, _restore_file, _classswitch_file, _copy_file, _rename_file, _listobjects, \ |
| 14 | + _op_meta |
14 | 15 | from .logger import logger |
15 | 16 | from .util import _check_dict, ufile_put_url, ufile_post_url, file_etag, ufile_uploadhit_url, ufile_getfilelist_url, \ |
16 | 17 | mimetype_from_file, ufile_restore_url, ufile_classswitch_url, ufile_copy_url, ufile_rename_url, \ |
17 | | - ufile_listobjects_url |
| 18 | + ufile_listobjects_url, ufile_op_meta_url |
18 | 19 |
|
19 | 20 |
|
20 | 21 | class FileManager(BaseUFile): |
@@ -535,3 +536,35 @@ def listobjects(self, bucket, prefix=None, marker=None, maxkeys=None, delimiter= |
535 | 536 | logger.info(info_message) |
536 | 537 | url = ufile_listobjects_url(bucket, upload_suffix=self.__upload_suffix) |
537 | 538 | return _listobjects(url, header, param) |
| 539 | + |
| 540 | + def opMeta(self, bucket, key, metak, metav, op="set", header=None): |
| 541 | + """ |
| 542 | + 获取文件元数据 |
| 543 | +
|
| 544 | + :param bucket: string 类型,空间名称 |
| 545 | + :param key: string 类型,文件在空间中的名称 |
| 546 | + :param metak: string 类型,元数据的key |
| 547 | + :param metav: string 类型,元数据的value |
| 548 | + :param op: string 类型,操作类型,目前只支持set |
| 549 | + :param header: dict类型,http 请求header,键值对类型分别为string,比如{'User-Agent': 'Google Chrome'} |
| 550 | + :return: ret: 如果http状态码为[200, 204, 206]之一则返回None,否则如果服务器返回json信息则返回dict类型,键值对类型分别为string, unicode string类型,否则返回空的dict |
| 551 | + :return: ResponseInfo: 响应的具体信息,UCloud UFile 服务器返回信息或者网络链接异常 |
| 552 | + """ |
| 553 | + if header is None: |
| 554 | + header = dict() |
| 555 | + else: |
| 556 | + _check_dict(header) |
| 557 | + |
| 558 | + if 'User-Agent' not in header: |
| 559 | + header['User-Agent'] = config.get_default('user_agent') |
| 560 | + header['Content-Type'] = 'application/json' |
| 561 | + |
| 562 | + auth = self.authorization('post', bucket, key, header, action="opmeta") |
| 563 | + header['Authorization'] = auth |
| 564 | + data = { |
| 565 | + 'op': op, |
| 566 | + 'metak': metak, |
| 567 | + 'metav': metav |
| 568 | + } |
| 569 | + url = ufile_op_meta_url(bucket, key, upload_suffix=self.__upload_suffix) |
| 570 | + return _op_meta(url, json.dumps(data), header) |
0 commit comments