Upload file to HubSpot from Google Drive Media Object

Hey everyone,

What I am trying to achieve is to upload a file from google drive to HubSpot ( Or Meta AdCreative as an example ). The problem I am facing - looks like I can’t get the correct format of the MediaObject to send to HubSpot. Errr I get “Error 415 Unsupported Media Type”

Here is what I’ve tried so far ( the basically I’ve tried to pass every single variable from this code below. In my ideal world I would just pass the Google Drive URL to the file, so it sends the data to HubSpot. But unfortunately it doesnt work like that.
I’ve tried to get contents of the file, get url, get_bytes(), get hash. All for nothing :slight_smile:
Any hint would help, thanks!

Code Sample:

  folder = app_files.ad_creatives
  folder = folder.get("category1")
  files = list(folder.list_files())
  first_file_info = files[0]
  file_upload = first_file_info.get_bytes()
  image_url = first_file_info.url
  print('image_url:',image_url)
  # Convert the image URL to bytes and update the hash object
  hash_object = hashlib.sha256()
  hash_object.update(image_url.encode())
  # Get the hexadecimal representation of the hash
  image_hash = hash_object.hexdigest()

Found the solution, so it’s not relevant anymore.
Maybe it would help someone. But you should better create the ad in two steps:

  1. load the file using /adimages: Graph API Reference v18.0: Ad Image - Documentation - Meta for Developers
  2. Once done - you can use the hash of the loaded image in the ad.
1 Like