Skip to content Skip to sidebar Skip to footer

Reading Of A File From Google Cloud Storage Fails In A Python + Flask + Gunicorn + Nginx + Compute Engine App

Reading of a file downloaded from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app. Link to the code: https://github.com/samuq/CE-test . The l

Solution 1:

file.seek(0) helped to solve the problem; somehow I assume that after blob.download_to_file(file_name) the file reader isn't in the start of the file. Code:

    try:
        fd, path = tempfile.mkstemp()
        with os.fdopen(fd, 'w+') as prj_file:
            # do stuff with temp file
            prj_blob.download_to_file(prj_file)
            prj_file.seek(0)
            euref_fin.ImportFromWkt(prj_file.read())
            logger.log_text(str(euref_fin))
            logger.log_text('euref_fin printed!')
    finally:
        os.remove(path)

Post a Comment for "Reading Of A File From Google Cloud Storage Fails In A Python + Flask + Gunicorn + Nginx + Compute Engine App"