I have an API to upload multiple images. How do I implement image.read() for multiple files asynchronously or in a separate job, such that I can respond back as soon as possible without having to wait for all the operations on the images?
I have tried to pass the images as parameters in rq
queue.enqueue(upload_to_cloud, images), but got an error, TypeError: cannot serialize '_io.BufferedRandom' object
class ImageUpload(Resource):
def post(self):
# Getting the names of the uploaded files
images = request.files.getlist('images')
# I would want the next line to be executed asynchronously
image_file_dict = [{"name": image.filename, "blob": image.read()} for image in images]
job = redis_queue.enqueue(upload_images_async, image_file_dict)
return {"message": "Success", "job_id": job.id}, 200
Any help is highly appreciated, Thanks.