python - 是否可以使用 Google App Engine(不带 Google Compute Engine)通过 API 调用(使用 Python)将文件下载到 Google Cloud Storage

标签 python google-app-engine google-cloud-storage google-compute-engine

我在这里编写了一个Python程序,它连接了各个平台的API以用于文件下载。该程序当前正在我的本地计算机(笔记本电脑)上运行,没有任何问题(当然,所有下载的文件都保存到我的本地驱动器中)。

这是我真正的问题,如果没有 Google Compute Engine,是否可以使用 Google App Engine 部署相同的 python 程序?如果是,我如何将我的文件(通过 API 调用)保存到此处的 Google Cloud Storage?

谢谢。

最佳答案

这是一个网络应用程序吗?如果是这样,您可以使用 GOOGLE APP ENGINE standard 来部署它或flexible .

要将文件发送到 Cloud Storage,请尝试 python-docs-samples 中的示例存储库(文件夹 appengine/flexible/storage/):

# [START upload]
@app.route('/upload', methods=['POST'])
def upload():
    """Process the uploaded file and upload it to Google Cloud Storage."""
    uploaded_file = request.files.get('file')

    if not uploaded_file:
        return 'No file uploaded.', 400

    # Create a Cloud Storage client.
    gcs = storage.Client()

    # Get the bucket that the file will be uploaded to.
    bucket = gcs.get_bucket(CLOUD_STORAGE_BUCKET)

    # Create a new blob and upload the file's content.
    blob = bucket.blob(uploaded_file.filename)

    blob.upload_from_string(
        uploaded_file.read(),
        content_type=uploaded_file.content_type
    )

    # The public URL can be used to directly access the uploaded file via HTTP.
    return blob.public_url
# [END upload]

关于python - 是否可以使用 Google App Engine(不带 Google Compute Engine)通过 API 调用(使用 Python)将文件下载到 Google Cloud Storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50269040/

相关文章:

python - 安装旧版本的 scikit-learn

python - 递归抓取页面

google-app-engine - 如何动态设置AppEngine Gradle属性

amazon-s3 - 内容安全策略标准是否支持通配符路径?如果没有,为什么不呢?

google-app-engine - 如何在 Google Developers Console 中设置成本限制

node.js - 谷歌云函数 bucket.upload()

Python 2.7 : %d, %s 和 float()

python - 使用多个 ObjectId 在 Pymongo 中批量更新

java - 如何在 App Engine 应用程序中处理/_ah/bounce 端点通知

python - 如何在 Google App Engine 中使用 Python(和 boto)通过浏览器从 Amazon S3 下载文件?