
当記事では、BlobからFileに変換する方法とFileからBlobに変換する方法を記します。
どちらも簡単に行えます。
BlobからFileに変換
const blob = new Blob(['hoge'], { type: 'text/plain' })
const file = new File([blob], 'sample.txt', { type: blob.type })
FileからBlobに変換
const file = new File(['hoge'], 'sample.txt', { type: 'text/plain' })
const blob = new Blob([file], { type: file.type })
以上、BlobとFileの相互に変換する方法でした。