Yechiel Hadad
Yechiel Hadad

Reputation: 13

Images/Videos CDN URL - Detect file type/extension

I'm trying to implement Story Mention rendering according to IG messenger graph API.

IG webhooks sends the payload URL of the media as CDN URLs that are extensionless, which means I can't detect the file type(could be any kind of image or a video file). The purpose is to render the URL to an HTML element and to prevent saving some file extensions.

Did anybody find out how to get this information?

An example for IG CDN URL https://lookaside.fbsbx.com/ig_messaging_cdn/?asset_id=17952754300482708&signature=AbxVoHUcW3qKGZvE0FwrbpSEKBqkYGH9wFDUY9xnywlxxek8lWtrTwE173Sxhta9jbp0bgDiL17IpyiI82vqHGNPUD1wdMUZphwQOggW-_877cCI1BxaY_aDUZ8hj5OwmHK9E8OnSybqtMVmGXCX_hBF399t1Hb44zspeL3d9NWb9rib

Upvotes: 0

Views: 1338

Answers (2)

dabossperson
dabossperson

Reputation: 11

I was able to retrieve the content type by making a request with node-fetch.

const fetch = require('node-fetch');

const response = await fetch(mediaUrl, { method: 'HEAD' });
const contentType = response.headers.get('Content-Type');

Upvotes: 1

bela.bartha
bela.bartha

Reputation: 122

Python:

import requests
res = requests.head(url)
print res.headers

Upvotes: 0

Related Questions