title: how to upload image to google cloud storage using python 2.7
body: <p>I am following this guide:</p>
  
  <p><a href="https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/app-engine-cloud-storage-sample" rel="nofollow noreferrer">https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/app-engine-cloud-storage-sample</a></p>
  
  <p>and it only specified how to upload text files, but I want to upload image instead.
  I got this image data from front end: </p>
  
  <pre class="lang-js prettyprint-override"><code>const contentType = 'image/png';
  
  const b64toBlob = (b64Data, contentType='', sliceSize=512) =&gt; {
    const byteCharacters = atob(b64Data);
    const byteArrays = [];
  
    for (let offset = 0; offset &lt; byteCharacters.length; offset += sliceSize) {
      const slice = byteCharacters.slice(offset, offset + sliceSize);
  
      const byteNumbers = new Array(slice.length);
      for (let i = 0; i &lt; slice.length; i++) {
        byteNumbers[i] = slice.charCodeAt(i);
      }
  
      const byteArray = new Uint8Array(byteNumbers);
      byteArrays.push(byteArray);
    }
  
    const blob = new Blob(byteArrays, {type: contentType});
    return blob;
  }
  
  image = b64toBlob(image, contentType);
  
  //the above turns base64 into blobs
  
  var data= new FormData();
  data.append('image',image );
  data.append('pointerlocation',pointerlocation);
  
   $.ajax({
      url: "/update",
      data: data,
      processData: false,
  contentType: false,
      type: "POST",
     success: function(result) {   
      $("#testimg").attr({ "src": `data:image/png;base64,${image}` });
  
  }
  });
  </code></pre>
  
  <p>This is what I got right now in python</p>
  
  <pre class="lang-py prettyprint-override"><code>image=self.request.get('image')#gets image
  pointerlocation=self.request.get('pointerlocation')#just location of where the image is on my website
  upload_file(image,pointerlocation)
  
  def upload_file(image,pointerlocation):
      bucket_name = os.environ.get(
              'mosaictest', app_identity.get_default_gcs_bucket_name())
      bucket = '/' + bucket_name
      filename = bucket + '/'+pointerlocation
      write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1)
      with cloudstorage.open(
              filename, 'w', content_type='image/png',
              retry_params=write_retry_params) as cloudstorage_file:
      #pseudocode-----------------------------------
              cloudstorage_file.addfile(image)
              url=get public url of(filename)
      return url
  #---------------------------------------------------
  
  </code></pre>
  
  <p>I have been stuck on this question for over 2 weeks because google apprently dropped support for python 2.7 and this is the only thing that even came close to working</p>
  
  <p><a href="https://cloud.google.com/storage/docs/reference/libraries" rel="nofollow noreferrer">https://cloud.google.com/storage/docs/reference/libraries</a></p>