title: Transfer file from URL to Cloud Storage
body: <p>I'm a Ruby dev trying my hand at Google Cloud Functions written in Python and have hit a wall with transferring a remote file from a given URL to Google Cloud Storage (GCS).</p>
  
  <p>In an equivalent RoR app I download to the app's ephemeral storage and then upload to GSC.</p>
  
  <p>I am hoping there's a way to simply 'download' the remote file to my GCS bucket via the Cloud Function.</p>
  
  <p>Here's a simplified example of what I am doing with some comments, the real code fetches the URLs from a private API, but that works fine and isn't where the issue is.</p>
  
  <pre><code>from google.cloud import storage
  project_id = 'my-project'
  bucket_name = 'my-bucket'
  destination_blob_name = 'upload.test'
  storage_client = storage.Client.from_service_account_json('my_creds.json')
  
  # This works fine
  #source_file_name = 'localfile.txt'
  
  # When using a remote URL I get 'IOError: [Errno 2] No such file or directory'
  source_file_name = 'http://www.hospiceofmontezuma.org/wp-content/uploads/2017/10/confused-man.jpg'
  
  def upload_blob(bucket_name, source_file_name, destination_blob_name):
      bucket = storage_client.get_bucket(bucket_name)
      blob = bucket.blob(destination_blob_name)
      blob.upload_from_filename(source_file_name)
  
  upload_blob(bucket_name, source_file_name, destination_blob_name)
  </code></pre>
  
  <p>Thanks in advance.</p>