|
| 1 | +import asyncio |
| 2 | +import argparse |
| 3 | +import alibabacloud_oss_v2 as oss |
| 4 | +import alibabacloud_oss_v2.aio as oss_aio |
| 5 | + |
| 6 | +parser = argparse.ArgumentParser(description="get object sample") |
| 7 | +parser.add_argument('--region', help='The region in which the bucket is located.', required=True) |
| 8 | +parser.add_argument('--bucket', help='The name of the bucket.', required=True) |
| 9 | +parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS') |
| 10 | +parser.add_argument('--key', help='The name of the object.', required=True) |
| 11 | + |
| 12 | + |
| 13 | +async def main(): |
| 14 | + |
| 15 | + args = parser.parse_args() |
| 16 | + |
| 17 | + # Loading credentials values from the environment variables |
| 18 | + credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider() |
| 19 | + |
| 20 | + # Using the SDK's default configuration |
| 21 | + cfg = oss.config.load_default() |
| 22 | + cfg.credentials_provider = credentials_provider |
| 23 | + cfg.region = args.region |
| 24 | + if args.endpoint is not None: |
| 25 | + cfg.endpoint = args.endpoint |
| 26 | + |
| 27 | + client = oss_aio.AsyncClient(cfg) |
| 28 | + |
| 29 | + result = await client.get_object(oss.GetObjectRequest( |
| 30 | + bucket=args.bucket, |
| 31 | + key=args.key, |
| 32 | + )) |
| 33 | + |
| 34 | + # Under the async mode, the data has been loaded into memory |
| 35 | + #print(f'content:{result.body.content}') |
| 36 | + |
| 37 | + print(f'status code: {result.status_code},' |
| 38 | + f' request id: {result.request_id},' |
| 39 | + f' content length: {result.content_length},' |
| 40 | + f' content range: {result.content_range},' |
| 41 | + f' content type: {result.content_type},' |
| 42 | + f' etag: {result.etag},' |
| 43 | + f' last modified: {result.last_modified},' |
| 44 | + f' content md5: {result.content_md5},' |
| 45 | + f' cache control: {result.cache_control},' |
| 46 | + f' content disposition: {result.content_disposition},' |
| 47 | + f' content encoding: {result.content_encoding},' |
| 48 | + f' expires: {result.expires},' |
| 49 | + f' hash crc64: {result.hash_crc64},' |
| 50 | + f' storage class: {result.storage_class},' |
| 51 | + f' object type: {result.object_type},' |
| 52 | + f' version id: {result.version_id},' |
| 53 | + f' tagging count: {result.tagging_count},' |
| 54 | + f' server side encryption: {result.server_side_encryption},' |
| 55 | + f' server side data encryption: {result.server_side_data_encryption},' |
| 56 | + f' server side encryption key id: {result.server_side_encryption_key_id},' |
| 57 | + f' next append position: {result.next_append_position},' |
| 58 | + f' expiration: {result.expiration},' |
| 59 | + f' restore: {result.restore},' |
| 60 | + f' process status: {result.process_status},' |
| 61 | + f' delete marker: {result.delete_marker},' |
| 62 | + ) |
| 63 | + |
| 64 | + await client.close() |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + asyncio.run(main()) |
0 commit comments