title: Is it possible to load a file from a cloud storage bucket object by its local path on Google Cloud Platform using App Engine?
body: <p>I am creating a web application that prompts the user to upload a file, which is stored in a Google Cloud Storage bucket. I use a parsing function (package on pip to extract the data, which takes a filepath and loads the specified file.</p>
  
  <p>The path for the file in the bucket is 
  <code>gs://my_bucket/myfile.ged</code>, 
  but this file can't be found when I pass the path to the parsing function. When run locally, it parses the file as expected. If I deploy the file in the project folder with the script, it works. But when run on App engine on Google Cloud Platform, it cannot find the file. </p>
  
  <p>The problem is similar to described <a href="https://stackoverflow.com/questions/51921142/how-to-load-a-model-saved-in-joblib-file-from-google-cloud-storage-bucket">here</a>. This is how I would expect it to work.</p>
  
  <pre><code>f = request.files['fileToUpload']
  blob = bucket.blob("myfile.ged")
  blob.upload_from_file(f)
  gs_path = 'gs://my_bucket/myfile.ged'
  parsing_function(gs_path)
  </code></pre>
  
  <p>And I guess I shouldn't be too surprised that the following testing function always returns 'empty':</p>
  
  <pre><code>def testing():
      var = 'emtpy'
  
      filename = 'gs://my_bucket/myfile.ged'
  
      if(os.path.exists(filename)):
          var = 'filename'
  
      else:
          blobs = bucket.list_blobs()
          for blob in blobs:
              if(os.path.exists(blob.path)):
                  var = blob.path
  
      return var
  </code></pre>
  
  <p>I've tried using the temp_file method, which gives the <code>TypeError: expected str, bytes or os.PathLike object, not _TemporaryFileWrapper</code></p>
  
  <pre><code> with TemporaryFile() as temp_file:
       blob.download_to_file(temp_file)
       temp_file.seek(0)
       parsing_function(gs_path)
  </code></pre>
  
  <p>I've also tried:</p>
  
  <ul>
  <li>Obtaining the blob.path, but it comes in a format /b/my_bucket/o/myfile.ged that also can't be found.</li>
  <li><p>The I/O method described <a href="https://stackoverflow.com/questions/51921142/how-to-load-a-model-saved-in-joblib-file-from-google-cloud-storage-bucket">here</a>:</p>
  
  <pre><code>filepath = BytesIO()
  blob.download_to_file(filepath)
  parsing_function(filepath)  
  </code></pre></li>
  </ul>
  
  <p>But this also retuns the <code>TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO</code></p>
  
  <p>So after an exhaustive search, I've come here for help. 
  Any suggestions, or alternatives would be greatly appreciated.</p>