Asynchronously upload images to Cloudinary using the Python API
I am trying to asynchronously upload images to Cloudinary using the Python API.
The [documentation][1] states the following is required to upload an image.
result = cloudinary.uploader.upload(file, **options)
Since, I would like to upload asynchronously, it appears I need to set the "async" option to True (also in the documentation).
> async (Boolean): Tells Cloudinary whether to perform the upload
> request in the background (asynchronously). Default: false.
Since options has **, as explained in [this SO post][2], I assume that the function accepts keyword arguments like so.
response = await cloudinary.uploader.upload(img, async=True)
However, when I run my script, I get the following error:
File "async_upload.py", line 16
response = await cloudinary.uploader.upload(img, async=True)
^ SyntaxError: invalid syntax
**How do I upload multiple images asynchronously in Cloudinary?**
[1]: https://cloudinary.com/documentation/image_upload_api_reference
[2]: https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters
-
Hi @Patrick,
I apologize for the delay.
Can you clarify if you are trying to do the call asynchronously on your end or through Cloudinary? By adding the async=True parameter, the request is processed in the background. When using the async=True parameter, the notification_url="www.example.com/myendpoint" can be added to let you know when the upload has completed. However, it should not take long to process the request.
I am looking to your update.
0 -
Hey Daniel. Unfortunately, the problem I'm having is that the Python interpreter won't run my code with async=True flag since "async" is now a reserved word in Python 3.
0 -
We need to gather more details to understand what may be the issue. I was able to a python3 project with async=True. Can you try running this/modifying this script to what you have, and send us the stack trace.
----
import cloudinary
import cloudinary.uploader
import cloudinary.api# Prints current version of Python being used.
import sys
print(sys.version + "\n")upload = cloudinary.uploader.upload("path/to/file", async=True, notification_url="www.example.com/myendpoint");
print(upload)----
If you wish to have a private conversation about this, please open a support ticket at https://support.cloudinary.com/hc/en-us/requests/new and address it to me.
0 -
Hi Daniel, the following was a reply to a post I made about this issue on the Cloudinary Community Facebook page. I believe the issue is specifically related to Python 3.7 (my apologies). Additionally, it appears async parameter doesn't actually work per the open github issue. Are you able to confirm?
async is a reserved word starting in Python 3.7, but not in earlier versions of Python. Cloudinary should probably update their library to rename the parameter. However. in the meantime, I believe you should be able to pass in the parameter using cloudinary.uploader.upload(image", **{'async': True}).
(That being said, a GitHub issue indicates the async parameter doesn't actually work anyway at the moment: https://github.com/cloudinary/pycloudinary/issues/84)0 -
Hi @Patrick,
I really apologize for the delay.
There is a current issue with the `async` keyword on Python 3.7 conflicting with the async parameter on Cloudinary. I've informed our dev team and they are aware of this issue. They are looking into possible solutions.
Once I receive any updates from them, I will let you know.
1 -
Thanks for the update Daniel!
0 -
5 months have past and this is still an issue. Any updates?
0 -
@Patrick @Kyle
We have a temporary workaround:
async_option = {"async": True} uploader.upload(TEST_IMAGE, **async_option)
Let me know if this is helpful.
0 -
I saw that. We will use that workaround for now, thanks. Hoping for a better solution, as this is kind of ugly.
0 -
@Daniel, I have run into the same issue and have used the workaround for now. Is a solution for this being worked on?
0 -
@Deven
We currently do not have an eta for replacing the workaround, but we I receive an update I will be glad to share it.
0 -
Is there an update to this?
Two years later, still an issue and we're at Python 3.9.0 -
Hi Danny,
There isn't an update so far.
As my colleague Eric mentioned in the ticket you also created, please use the workaround:
async_option = {"async": True}
In the meantime, we are checking internally with the team.
Best,
Loic
0
Post is closed for comments.
Comments
13 comments