importpkg_resourcesfromgoogle.appengine.extimportvendor# Set PATH to your libraries folder.PATH='lib'# Add libraries installed in the PATH folder.vendor.add(PATH)# Add libraries to pkg_resources working set to find the distribution.pkg_resources.working_set.add_entry(PATH)
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThe App Engine client library for Cloud Storage in Python 2 is not available in newer runtimes like Python 3, necessitating a migration to the Cloud Client Library for Cloud Storage.\u003c/p\u003e\n"],["\u003cp\u003eMigrating to the Cloud Client Library does not change existing data objects or permissions in Cloud Storage buckets, as the new library can access existing buckets seamlessly.\u003c/p\u003e\n"],["\u003cp\u003eWhile the Cloud Client Library supports all core functionalities of the App Engine library, it also introduces new features like bucket labeling and retrieving older object versions, but listing objects is no longer asynchronous.\u003c/p\u003e\n"],["\u003cp\u003eAccess control in Cloud Storage can be managed through ACLs (as with the App Engine library) or the recommended uniform bucket-level access, although switching existing buckets to the latter might require significant changes.\u003c/p\u003e\n"],["\u003cp\u003eTo migrate, developers must install the Cloud Client Library, update their code to use the new library's methods, test the changes, and then deploy the updated application, including adding necessary libraries to \u003ccode\u003eapp.yaml\u003c/code\u003e and \u003ccode\u003erequirements.txt\u003c/code\u003e files.\u003c/p\u003e\n"]]],[],null,["# Migrating to the Cloud Client Library for Storage\n\n[Cloud Storage](/storage/docs) enables\nyour application to serve large data objects such as video or image files, and\nenables your users to upload large data files. In the Python 2 runtime,\nApp Engine provides its own client library for writing and reading\nobjects in Cloud Storage. This App Engine library is not available\nin newer App Engine runtimes, including the Python 3 runtime.\n\nIf your Python 2 app uses the `GoogleAppEngineCloudStorageClient` library, you\nneed to migrate to the Cloud Client Library for Cloud Storage before you can\nrun the app in the Python 3 runtime. Note that you only need to migrate your\napp to use a new client library. **All of the data objects and permissions in\nyour existing Cloud Storage buckets remain unchanged, and you can access\nyour existing buckets using the new client library**.\n\nComparison of the App Engine and Cloud Client Libraries\n-------------------------------------------------------\n\nSimilarities:\n\n- The Cloud Client Library supports all of the Cloud Storage features enabled\n by the App Engine client library, such as reading, writing, removing,\n and listing objects. Migration should require only small changes\n to your code.\n\n The Cloud Client Library also supports additional features,\n such as creating and [labeling](/storage/docs/using-bucket-labels) buckets, and [retrieving older versions\n of objects](/storage/docs/object-versioning).\n\nDifferences:\n\n- In the App Engine library, the function that retrieves a list of\n objects works [asynchronously](/appengine/docs/legacy/standard/python/googlecloudstorageclient/functions#listbucket).\n The Cloud Client Library doesn't provide an asynchronous function for listing\n objects, though you can use paging and iterate through a small set of objects.\n\n- The App Engine client library requires you to use\n access control lists (ACL) to control access to buckets and objects.\n However, Cloud Storage and the Cloud Client Library support two systems\n for granting users permission to access your buckets and objects: ACLs\n and [uniform bucket-level access](/storage/docs/uniform-bucket-level-access). Uniform bucket-level access provides a\n simpler, consistent access control experience across all of your Cloud resources.\n\n All ACLs that you used with the App Engine client library remain in\n effect for your existing buckets after you migrate to the Cloud Client Library,\n and you can continue to use ACLs if needed.\n\n If uniform bucket-level access meets your needs, we recommend you use this\n simpler system for any new buckets you create. While you can convert existing\n buckets to use uniform bucket-level access, this may require significant\n changes to how your app secures access to its storage objects.\n\nCode samples:\n\n- Basic storage operations\n [using the App Engine APIs](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/storage/appengine-client/main.py)\n\n- Basic storage operations\n [using the Cloud client library for Cloud Storage](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/migration/storage/main.py)\n\nBefore you start migrating\n--------------------------\n\nIf you have not done so already, set up your\n[Python development environment](/python/docs/setup) to use a Python version\nthat is compatible with Google Cloud, and install testing tools for creating\nisolated Python environments.\n\n### Understanding Cloud Storage permissions\n\nBy default, your app's [auto-created default service account](/iam/docs/service-accounts#default)\nhas read and write privileges to the buckets in your project, and it has\nfull rights to the objects it creates, both before and after migration.\n\nIf you used a different service account or user account to secure access to\nyour Cloud Storage buckets and objects, be sure you continue to use the\nsame accounts and [authentication techniques](/docs/authentication#service-accounts) before and after migration.\n\nOverview of the migration process\n---------------------------------\n\nTo migrate your Python app to use the Cloud Client Library for Cloud Storage\ninstead of the App Engine client library:\n\n1. [Install](#install) the Cloud Client Library for Cloud Storage.\n\n2. [Update](#update) your code to use the Cloud Client Library.\n\n3. [Test](#testing) your updates.\n\n4. [Deploy](#deploying) your app to App Engine.\n\nInstalling the Cloud Client Library for Cloud Storage\n-----------------------------------------------------\n\nTo make the Cloud Client Library for Cloud Storage available to your app\nwhen it runs in App Engine:\n\n1. Update the `app.yaml` file:\n\n 1. If you use Cloud Client Libraries, add the latest versions of `grpcio` and `setuptools` libraries.\n 2. Add the `ssl` library since this is required by Cloud Storage.\n\n The following is an example `app.yaml` file: \n\n runtime: python27\n threadsafe: yes\n api_version: 1\n\n libraries:\n - name: grpcio\n version: 1.0.0\n - name: setuptools\n version: 36.6.0\n - name: ssl\n version: latest\n\n Some client libraries don't need the SSL library. If you don't include the\n SSL library for a client library that needs it, you'll see an SSL error\n in the Logs Explorer when your app receives a request.\n2. Update the `requirements.txt` file by adding the Cloud Client Libraries\n for Cloud Storage to your list of dependencies:\n\n google-cloud-storage==1.24.1\n\n We recommend you use the 1.24.1 version of the Cloud Storage client\n library since it supports Python 2.7 apps.\n\n Then run `pip install -t lib -r requirements.txt` to update the list of\n available libraries for your app.\n3. For Python 2 apps, if your app is using built-in or copied libraries, you\n must specify those paths in the `appengine_config.py` file:\n\n import pkg_resources\n from google.appengine.ext import vendor\n\n # Set PATH to your libraries folder.\n PATH = 'lib'\n # Add libraries installed in the PATH folder.\n vendor.add(PATH)\n # Add libraries to pkg_resources working set to find the distribution.\n pkg_resources.working_set.add_entry(PATH)\n\n The `appengine_config.py` file in the preceding example assumes that the\n the `lib` folder is located in the current working directory. If you can't\n guarantee that `lib` will always be in the current working directory,\n specify the full path to the `lib` folder. For example: \n\n ```python\n import os\n path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')\n ```\n\nUpdating your code to use the Cloud Client Library\n--------------------------------------------------\n\n### Creating a Cloud Storage Client\n\nTo use the Cloud Client Library for Cloud Storage, create a [`Client`\nobject](/python/docs/reference/storage/latest/google.cloud.storage.client.Client). The client contains credentials and other\ndata needed to connect to Cloud Storage. For example: \n\n from google.cloud import https://cloud.google.com/python/docs/reference/storage/latest/\n\n client = https://cloud.google.com/python/docs/reference/storage/latest/.https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.client.Client.html()\n\nIn the [default authorization scenario described previously](#authorization),\nthe Cloud Storage client contains credentials from App Engine's\ndefault service account, which is authorized to interact with your project's\nbuckets and objects. If you aren't working in this default scenario, see\n[Application Default Credentials (ADC)](/docs/authentication/application-default-credentials)\nfor information on how to provide credentials.\n\n### Using Cloud Client Library methods\n\nThe following table summarizes which methods from the Cloud Client Library\nto use when implementing specific Cloud Storage features.\n| **Note:** See the [list of code samples](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/storage/cloud-client) and the [reference documentation](/python/docs/reference/storage/latest/google.cloud.storage.client.Client) for the Cloud Client Library.\n\nTesting your updates\n--------------------\n\nYou can test your updates to your app in a local environment, but all\nCloud Storage requests must be sent over the internet to an actual\nCloud Storage bucket. Neither App Engine nor Cloud Storage\nprovides a Cloud Storage emulator.\n\nFor more information about testing Python 2 apps, see [Using the local\ndevelopment server](/appengine/docs/legacy/standard/python/tools/using-local-server).\n\nFor more information about testing Python 3 apps, see [Testing and deploying\nyour application](/appengine/docs/standard/testing-and-deploying-your-app).\n\nDeploying your app\n------------------\n\nOnce you are ready to deploy your app, you should:\n\n1. [Test the app on\n App Engine](/appengine/docs/standard/testing-and-deploying-your-app#testing-on-app-engine).\n\n2. If the app runs without errors, [use traffic\n splitting](/appengine/docs/standard/splitting-traffic) to slowly\n ramp up traffic for your updated app. Monitor the app closely for any\n issues before routing more traffic to the updated app."]]