Skip to content

Instantly share code, notes, and snippets.

@piemme
Created December 5, 2022 09:44
Show Gist options
  • Save piemme/a149c8348f6b324da9e183fb9244c3c7 to your computer and use it in GitHub Desktop.
Save piemme/a149c8348f6b324da9e183fb9244c3c7 to your computer and use it in GitHub Desktop.
import {fileTypeFromStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const response = await fetch(url);
const fileType = await fileTypeFromStream(response.body);
console.log(fileType);
//=> {ext: 'jpg', mime: 'image/jpeg'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment