• <tfoot id='W01WW'></tfoot>

    <small id='W01WW'></small><noframes id='W01WW'>

          <bdo id='W01WW'></bdo><ul id='W01WW'></ul>
        <legend id='W01WW'><style id='W01WW'><dir id='W01WW'><q id='W01WW'></q></dir></style></legend>
        <i id='W01WW'><tr id='W01WW'><dt id='W01WW'><q id='W01WW'><span id='W01WW'><b id='W01WW'><form id='W01WW'><ins id='W01WW'></ins><ul id='W01WW'></ul><sub id='W01WW'></sub></form><legend id='W01WW'></legend><bdo id='W01WW'><pre id='W01WW'><center id='W01WW'></center></pre></bdo></b><th id='W01WW'></th></span></q></dt></tr></i><div id='W01WW'><tfoot id='W01WW'></tfoot><dl id='W01WW'><fieldset id='W01WW'></fieldset></dl></div>
      1. 如何通过 Python 脚本在 Google Cloud Storage 上上传字节图像

        How to upload a bytes image on Google Cloud Storage from a Python script(如何通过 Python 脚本在 Google Cloud Storage 上上传字节图像)
          <tbody id='4X1O3'></tbody>

          <small id='4X1O3'></small><noframes id='4X1O3'>

                <bdo id='4X1O3'></bdo><ul id='4X1O3'></ul>

                <tfoot id='4X1O3'></tfoot>

                • <legend id='4X1O3'><style id='4X1O3'><dir id='4X1O3'><q id='4X1O3'></q></dir></style></legend>
                  <i id='4X1O3'><tr id='4X1O3'><dt id='4X1O3'><q id='4X1O3'><span id='4X1O3'><b id='4X1O3'><form id='4X1O3'><ins id='4X1O3'></ins><ul id='4X1O3'></ul><sub id='4X1O3'></sub></form><legend id='4X1O3'></legend><bdo id='4X1O3'><pre id='4X1O3'><center id='4X1O3'></center></pre></bdo></b><th id='4X1O3'></th></span></q></dt></tr></i><div id='4X1O3'><tfoot id='4X1O3'></tfoot><dl id='4X1O3'><fieldset id='4X1O3'></fieldset></dl></div>
                  本文介绍了如何通过 Python 脚本在 Google Cloud Storage 上上传字节图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想通过 python 脚本将图像上传到 Google Cloud Storage.这是我的代码:

                  I want to upload an image on Google Cloud Storage from a python script. This is my code:

                  from oauth2client.service_account import ServiceAccountCredentials
                  from googleapiclient import discovery
                  
                  scopes = ['https://www.googleapis.com/auth/devstorage.full_control']
                  credentials = ServiceAccountCredentials.from_json_keyfile_name('serviceAccount.json', scop
                  es)
                  service = discovery.build('storage','v1',credentials = credentials)
                  
                  body = {'name':'my_image.jpg'}
                  
                  req = service.objects().insert(
                     bucket='my_bucket', body=body,
                     media_body=googleapiclient.http.MediaIoBaseUpload(
                        gcs_image, 'application/octet-stream'))
                  
                  resp = req.execute()
                  

                  如果 gcs_image = open('img.jpg', 'r') 代码可以正常工作并将我的图像正确保存在 Cloud Storage 上.如何直接上传字节图像?(例如来自 OpenCV/Numpy 数组:gcs_image = cv2.imread('img.jpg'))

                  if gcs_image = open('img.jpg', 'r') the code works and correctly save my image on Cloud Storage. How can I directly upload a bytes image? (for example from an OpenCV/Numpy array: gcs_image = cv2.imread('img.jpg'))

                  推荐答案

                  就我而言,我想将 PDF 文档从字节上传到云存储.

                  In my case, I wanted to upload a PDF document to Cloud Storage from bytes.

                  当我尝试以下操作时,它创建了一个包含我的字节字符串的文本文件.

                  When I tried the below, it created a text file with my byte string in it.

                  blob.upload_from_string(bytedata)
                  

                  为了使用字节字符串创建一个实际的 PDF 文件,我必须这样做:

                  In order to create an actual PDF file using the byte string I had to do:

                  blob.upload_from_string(bytedata, content_type='application/pdf')
                  

                  我的字节数据是b64encoded,所以我也先b64decode.

                  My byte data was b64encoded, so I also had b64decode it first.

                  这篇关于如何通过 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中的另一个文件中查找一个文本文件的条目)

                        <tbody id='EsSdy'></tbody>

                      <small id='EsSdy'></small><noframes id='EsSdy'>

                        <bdo id='EsSdy'></bdo><ul id='EsSdy'></ul>

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

                            <tfoot id='EsSdy'></tfoot>
                          1. <legend id='EsSdy'><style id='EsSdy'><dir id='EsSdy'><q id='EsSdy'></q></dir></style></legend>