Created
December 9, 2021 16:13
-
-
Save devxoul/81f07394659788489c59d9193e5d3fff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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