<legend id='NtwZ6'><style id='NtwZ6'><dir id='NtwZ6'><q id='NtwZ6'></q></dir></style></legend>

      <bdo id='NtwZ6'></bdo><ul id='NtwZ6'></ul>
    <i id='NtwZ6'><tr id='NtwZ6'><dt id='NtwZ6'><q id='NtwZ6'><span id='NtwZ6'><b id='NtwZ6'><form id='NtwZ6'><ins id='NtwZ6'></ins><ul id='NtwZ6'></ul><sub id='NtwZ6'></sub></form><legend id='NtwZ6'></legend><bdo id='NtwZ6'><pre id='NtwZ6'><center id='NtwZ6'></center></pre></bdo></b><th id='NtwZ6'></th></span></q></dt></tr></i><div id='NtwZ6'><tfoot id='NtwZ6'></tfoot><dl id='NtwZ6'><fieldset id='NtwZ6'></fieldset></dl></div>

    1. <small id='NtwZ6'></small><noframes id='NtwZ6'>

    2. <tfoot id='NtwZ6'></tfoot>

    3. 使用 Python 在 Google Cloud Storage 存储桶中创建/上传新文件

      Creating/Uploading new file at Google Cloud Storage bucket using Python(使用 Python 在 Google Cloud Storage 存储桶中创建/上传新文件)

            <i id='hYl6q'><tr id='hYl6q'><dt id='hYl6q'><q id='hYl6q'><span id='hYl6q'><b id='hYl6q'><form id='hYl6q'><ins id='hYl6q'></ins><ul id='hYl6q'></ul><sub id='hYl6q'></sub></form><legend id='hYl6q'></legend><bdo id='hYl6q'><pre id='hYl6q'><center id='hYl6q'></center></pre></bdo></b><th id='hYl6q'></th></span></q></dt></tr></i><div id='hYl6q'><tfoot id='hYl6q'></tfoot><dl id='hYl6q'><fieldset id='hYl6q'></fieldset></dl></div>
            <tfoot id='hYl6q'></tfoot>
          1. <small id='hYl6q'></small><noframes id='hYl6q'>

              <tbody id='hYl6q'></tbody>

            <legend id='hYl6q'><style id='hYl6q'><dir id='hYl6q'><q id='hYl6q'></q></dir></style></legend>

              • <bdo id='hYl6q'></bdo><ul id='hYl6q'></ul>

              • 本文介绍了使用 Python 在 Google Cloud Storage 存储桶中创建/上传新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何使用 Python 和可用的客户端库在 Google Cloud Storage 中创建新的空文件?

                How to create new empty files in Google Cloud Storage using Python with client libraries available?

                或者如何使用 blob 函数upload_from_filename()"将新文件上传到选定的存储桶?要初始化 blob 对象,我们应该在云存储桶中已有文件,但我想创建一个新文件名,并从本地存储的文件中复制内容.我想用 python 来做这个.

                Or how to upload a new file to a selected bucket using blob function "upload_from_filename()" ? To initialize the blob object we should have file already in the cloud bucket, but I want to create a new file name, and copy the content from the file stored locally. I want to do this using python.

                提前致谢

                推荐答案

                首先需要加载库

                import google.cloud.storage
                

                假设您创建了一个服务帐户并在某处加载了 JSON 文件,您需要创建一个客户端对象

                Assuming you have a service account created and JSON file loaded somewhere, you need to create a client object

                storage_client = google.cloud.storage.Client.from_service_account_json('JSON filepath')
                

                那么你需要提供创建一个bucket对象

                Then you need to provide the create a bucket object

                bucket = storage_client.get_bucket('bucket_name')
                

                现在定义存储桶中的路径和文件名

                Now define the path within your bucket and the file name

                d = 'path/name'
                

                blob 方法创建新文件,也是一个对象.

                The blob method create the new file, also an object.

                d = bucket.blob(d)
                

                upload_from_string 方法添加文件的内容.还有其他方法可以让您执行不同的任务.

                The upload_from_string method add the contents of the file. There are other methods allowing you to perform different tasks.

                d.upload_from_string('V')
                

                第一次准备好前几个步骤所需的时间最长.

                The first few steps take the longest to be ready the first time.

                祝你好运!

                这篇关于使用 Python 在 Google Cloud Storage 存储桶中创建/上传新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                  1. <tfoot id='5k74J'></tfoot>
                    <i id='5k74J'><tr id='5k74J'><dt id='5k74J'><q id='5k74J'><span id='5k74J'><b id='5k74J'><form id='5k74J'><ins id='5k74J'></ins><ul id='5k74J'></ul><sub id='5k74J'></sub></form><legend id='5k74J'></legend><bdo id='5k74J'><pre id='5k74J'><center id='5k74J'></center></pre></bdo></b><th id='5k74J'></th></span></q></dt></tr></i><div id='5k74J'><tfoot id='5k74J'></tfoot><dl id='5k74J'><fieldset id='5k74J'></fieldset></dl></div>

                      <bdo id='5k74J'></bdo><ul id='5k74J'></ul>

                      1. <small id='5k74J'></small><noframes id='5k74J'>

                        <legend id='5k74J'><style id='5k74J'><dir id='5k74J'><q id='5k74J'></q></dir></style></legend>

                          <tbody id='5k74J'></tbody>