1

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.

  • Did you manage to solve this? I'm stuck here as well. I think it has something to do with how python is reading the files, rather the file handle – princelySid Dec 02 '19 at 22:11

0 Answers0