待捕
async def _upload_frame_to_s3_async(self, video):
print('上傳frame slice', video)
frame_list = glob.glob(os.path.join(video, '*.jpg'))
video_name = video.split('/')[-1]
filename_list = [os.path.split(frame)[1] for frame in frame_list]
target_list = [
(os.path.join(video, filename), os.path.join(
'Car22', 'origin_img', video_name, filename))
for filename in filename_list
]
session = aioboto3.Session()
semaphore = asyncio.Semaphore(1000)
async def upload_file(bucket, path, key):
async with semaphore:
return await bucket.upload_file(path, key, ExtraArgs={'ContentType': 'image/jpeg'})
async with session.resource("s3") as s3:
bucket = await s3.Bucket('flow-drive-internal')
await asyncio.gather(*[upload_file(bucket, path, key) for path, key in target_list])