首页 > 解决方案 > 如何通过 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) 作为输出时,它也无济于事。

标签: pythonimagefunctioncurlcloud

解决方案


推荐阅读