Skip to content

Instantly share code, notes, and snippets.

@rahulbanerjee26
Created September 25, 2022 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulbanerjee26/6aca4be55d0620c6fbcdd373edf5f241 to your computer and use it in GitHub Desktop.
Save rahulbanerjee26/6aca4be55d0620c6fbcdd373edf5f241 to your computer and use it in GitHub Desktop.
def upload_media(self, filePath, alt_text="", caption=""):
new_session = self.session
data = open(filePath, "rb").read()
new_session.headers.update(
{
"Content-Type": "",
"Content-Disposition": f'attachment; filename="{filePath}"',
}
)
upload_media_endpoint = f"{self._endpoint}media"
response = new_session.post(
upload_media_endpoint,
json={"alt_text": alt_text, "caption": caption},
data=data,
)
return response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment