Skip to content

Instantly share code, notes, and snippets.

@devxoul
Created December 9, 2021 16:13
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 devxoul/81f07394659788489c59d9193e5d3fff to your computer and use it in GitHub Desktop.
Save devxoul/81f07394659788489c59d9193e5d3fff to your computer and use it in GitHub Desktop.
const getFileFromURL = async (url: string): Promise<File> => {
const result = await fetch(url)
const buffer = await result.arrayBuffer()
const blob = new Blob([buffer])
const file = new File([blob], url.split('/')[1])
return file
}
// Usage
const someFile: File
const fileURL = URL.createObjectURL(someFile)
const newFile = getFileFromURL(fileURL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment