【问题标题】:Asynchronously upload images to Cloudinary using the Python API使用 Python API 将图像异步上传到 Cloudinary
【发布时间】:2019-01-05 04:07:44
【问题描述】:

我正在尝试使用他们的 Python API 将图像异步上传到 Cloudinary。

他们的documentation 声明上传图片需要以下内容。

result = cloudinary.uploader.upload(file, **options)

由于我想异步上传,看来我需要将“异步”选项设置为 True(也在文档中)。

async (Boolean): 告诉 Cloudinary 是否执行上传 在后台请求(异步)。默认值:假。

由于 options 具有 **,如 this SO post 中所述,我假设该函数接受这样的关键字参数。

response = await cloudinary.uploader.upload(img, async=True)

但是,当我运行脚本时,出现以下错误:

  File "async_upload.py", line 16
    response = await cloudinary.uploader.upload(img, async=True)
                                                         ^ SyntaxError: invalid syntax

如何在 Cloudinary 中异步上传多张图片?

【问题讨论】:

  • async 现在是 Python 的保留关键字。 API 库似乎比这更旧。
  • @KlausD。啊啊啊这很有意义!嗯...我想知道我应该改用什么:L

标签: python asynchronous syntax parameters cloudinary


【解决方案1】:

没有特定的 Cloudinary 方法。您可以使用 asyncio 异步上传。 https://medium.freecodecamp.org/a-guide-to-asynchronous-programming-in-python-with-asyncio-232e2afa44f6

【讨论】:

  • 我相信不带 async 标志的 cloudinary.uploader.upload(img) 是一个阻塞函数,因此使用带有同步函数调用的 asyncio 不会对我现有的同步解决方案带来任何性能提升。
猜你喜欢
  • 2019-04-17
  • 2021-03-20
  • 2017-06-03
  • 2015-02-21
  • 2017-07-12
  • 2014-11-25
  • 2021-09-03
  • 2018-03-15
  • 2017-12-01
相关资源
最近更新 更多