code: def download_to_temp_file(url):
      global CP_TEMP_DIR
      parsed = urlparse(url)
      scheme = parsed.scheme
      netloc = parsed.netloc
      path = parsed.path
      queries = parse_qs(parsed.query)
      if "name" in queries:
          path = queries["name"][0]
      ext = os.path.splitext(path)[-1]
  
      # Handle Google Cloud Storage URLs.
      if scheme == "gs":
          return _handle_gcs_url(netloc, ext, path)
      else:
          # Handle Amazon Web Services URLs.
          if scheme == "s3":
              client = boto3.client("s3")
              bucket_name, key = (
                  re.compile("s3://([\w\d\-\.]+)/(.*)")
                  .search(url)
                  .groups()
              )
              # Get pre-signed URL.
              url = client.generate_presigned_url(
                  "get_object",
                  Params={
                      "Bucket": bucket_name,
                      "Key": key.replace("+", " "),
                  },
              )
          # Download object from URL.
          src = urlopen(url)
          dest_file = tempfile.NamedTemporaryFile(
              suffix=ext, delete=False, dir=CP_TEMP_DIR.name
          )
          try:
              shutil.copyfileobj(src, dest_file)
          except Exception as e:
              LOGGER.error(
                  f"Unable to download image to temp file. {e}"
              )
              return None
          finally:
              dest_file.close()
          return dest_file.name
  
imports: import logging
  import os
  import re
  import shutil
  import sys
  import tempfile
  import urllib.request
  from urllib.parse import parse_qs, unquote, urlparse
  from urllib.request import urlopen
  import boto3
  import numpy
  import pkg_resources
  import scipy.io
  from google.cloud import storage
  from google.cloud.exceptions import NotFound
  from google.auth.exceptions import DefaultCredentialsError
  from ..constants.image import ALL_IMAGE_EXTENSIONS, FILE_SCHEME, PASSTHROUGH_SCHEMES, SUPPORTED_MOVIE_EXTENSIONS
  from ..constants.measurement import FTR_WELL
  from .measurement import is_well_column_token, is_well_row_token
label_desc: Use image node_id 19 for calling a global function with example usage: download_to_temp_file(url) and returns: _handle_gcs_url, dest_file, None