云功能:如何上传包含图像的文件夹



我想使用谷歌云平台的云功能部署一个机器人。我的代码是用python编写的,但我想添加一个文件夹,里面有很多图片,我的机器人会在推特上推特。我想这样做,以确保我的机器人将全天候运行,并添加到Cloud Scheduler来安排我的推文。

有可能以某种方式上传图像文件夹吗?

我试图将我的所有文件上传到一个.zip文件中并上传到那里,但它将无法构建。单独使用代码运行良好。我使用谷歌开发者平台有一段时间了,但我从未尝试过。

以下是来自谷歌云平台的错误:

{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"status": {
"code": 3,
"message": "Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation."
},
"authenticationInfo": {
"principalEmail": "robertmaximus383@gmail.com"
},
"serviceName": "cloudfunctions.googleapis.com",
"methodName": "google.cloud.functions.v1.CloudFunctionsService.CreateFunction",
"resourceName": "projects/twitter-post-bot/locations/us-central1/functions/twitter-post"
},
"insertId": "-63htw4d2bfe",
"resource": {
"type": "cloud_function",
"labels": {
"project_id": "twitter-post-bot",
"region": "us-central1",
"function_name": "twitter-post"
}
},
"timestamp": "2022-01-31T08:06:24.986674Z",
"severity": "ERROR",
"logName": "projects/twitter-post-bot/logs/cloudaudit.googleapis.com%2Factivity",
"operation": {
"id": "operations/dHdpdHRlci1wb3N0LWJvdC91cy1jZW50cmFsMS90d2l0dGVyLXBvc3QvZEt5N24yX1NjTE0",
"producer": "cloudfunctions.googleapis.com",
"last": true
},
"receiveTimestamp": "2022-01-31T08:06:25.259596536Z"
}

2

{
"textPayload": "Function cannot be initialized. Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#loggingn",
"insertId": "000000-5838e3b2-5d8d-4187-86ca-97327d016436",
"resource": {
"type": "cloud_function",
"labels": {
"region": "us-central1",
"function_name": "twitter-post",
"project_id": "twitter-post-bot"
}
},
"timestamp": "2022-01-31T08:06:24.930142467Z",
"severity": "ERROR",
"labels": {
"execution_id": ""
},
"logName": "projects/twitter-post-bot/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"receiveTimestamp": "2022-01-31T08:06:25.532983237Z"
}

3

{
"textPayload": "Traceback (most recent call last):n  File "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>n    sys.exit(_cli())n  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 829, in __call__n    return self.main(*args, **kwargs)n  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 782, in mainn    rv = self.invoke(ctx)n  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 1066, in invoken    return ctx.invoke(self.callback, **ctx.params)n  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 610, in invoken    return callback(*args, **kwargs)n  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/_cli.py", line 37, in _clin    app = create_app(target, source, signature_type)n  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/__init__.py", line 288, in create_appn    spec.loader.exec_module(source_module)n  File "<frozen importlib._bootstrap_external>", line 850, in exec_modulen  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removedn  File "/workspace/main.py", line 2, in <module>n    from twitter import *nModuleNotFoundError: No module named 'twitter'",
"insertId": "000000-438da477-ef7c-4c81-98a2-21bdccc7ca12",
"resource": {
"type": "cloud_function",
"labels": {
"project_id": "twitter-post-bot",
"function_name": "twitter-post",
"region": "us-central1"
}
},
"timestamp": "2022-01-31T08:06:24.238Z",
"severity": "ERROR",
"labels": {
"execution_id": ""
},
"logName": "projects/twitter-post-bot/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"receiveTimestamp": "2022-01-31T08:06:25.532983237Z"
}

当您在云函数上部署代码时,代码会被获取、编译和打包在一个容器中(使用Buildpack(,并部署在云函数中。

在您的情况下,代码不是编译的,而是打包的

源代码保存在容器中,但保存在特定的目录中。我在Golang写了一篇关于样本的文章,但你可以找到静态文件的存储位置:/workspace/src/


这会解决你的问题,但我认为你有设计问题。静态和非结构化数据应该在您的云函数中。云存储是实现这一点的完美场所,它是一个更好、更可扩展的解决方案。

相关内容

  • 没有找到相关文章

最新更新