Можно ли загрузить файл в Google Cloud Storage с помощью вызова API (с Python) с помощью Google App Engine (без Google Compute Engine) - PullRequest
0 голосов
/ 10 мая 2018

Я написал программу на python, которая подключала API различных платформ для загрузки файлов здесь. В настоящее время программа работает на моем локальном компьютере (ноутбуке) без проблем (все загруженные файлы сохраняются на моем локальном диске, конечно).

Вот мой реальный вопрос, без Google Compute Engine, возможно ли развернуть ту же самую программу python, используя Google App Engine? Если да, как я могу сохранить свои файлы (через вызовы API) в Google Cloud Storage здесь?

Спасибо.

1 Ответ

0 голосов
/ 10 мая 2018

Это веб-приложение?Если это так, вы развертываете его, используя GOOGLE APP ENGINE standard или Flexible .

. Чтобы отправить файлы в облачное хранилище, попробуйте пример в python-docs-samples repo (папка 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]
...