python - 如何通过 curl 将图像文件发送到谷歌云函数并使用 python 读取?
问题描述
我想通过 curl 将 image.png 文件发送到谷歌云函数并对其进行 keras 模型预测。(这里没有指定型号..)
我查看了各种线程,但没有一个完全适合我的问题。(比如这个:How to use curl to send file to Google Cloud Function? I don't want to save the file on cloud storage...)关键部分是从给出的“请求”对象中获取“图像”实例google cloud函数上的python环境。
# the request instance is automatically created by google cloud functions
# in advance
def print_prediction(request):
result = 'Hello, you are looking good today!'
if request.method == 'POST':
image_raw = [request.form.get('image')]
result = 'show me whats in there'... + str(request) + str(image_raw)
return result
当我通过以下命令传递我的图像文件时,我希望“请求”变量(它在谷歌云函数中自动从请求传递到 python 环境)具有我可以通过 request.form 提取的“图像”之类的属性。得到()。
curl --form 'image=@path_to_image/some_image.png' https://provided-url-from-cloud-functions
为了了解请求对象具有哪些属性,我尝试了对象的各种打印,但我无法帮助自己。
上面函数执行 curl 命令后的输出是:
'告诉我那里有什么 http://europe-west1-chris-weather-app-1.cloudfunctions.net/' [POST]>[None]'
所以我认为我根本没有从请求中提取任何内容。当我使用 vars(request) 作为输出时,它也无济于事。
解决方案
推荐阅读
- android - Android SingleTask 和使用 StartActivity(Intent) 似乎调用 onCreate() 方法?
- postgresql - 在 AWS 上初始化 Prisma 2 + Postgres docker 时出错
- java - 在 Java 中有没有办法将对象引用传递给方法,在方法内部实例化它,并在方法外部访问它?
- html - 设置缩略图悬停跨度放大图像位置
- python - pyenv 如何在 OpenBSD 上检测 (e)readline?
- azure - 连接到 api 网关的自动缩放应用服务环境
- javascript - permissionOverwrites 不会注意到授予@everyone 角色的权限。我该如何解决?
- c++ - Visual Studio C++ ofstream 无法创建 .txt 文件,但可以创建其他类型
- python - 在 OpenPyXL 列中查找空白单元格
- r - Roxygen 链接到“[”方法