Donaldcwl / browser-image-compression

Image compression in web browser
MIT License
1.3k stars 160 forks source link

Always return Blob object #77

Closed desaikalpesh34 closed 4 years ago

desaikalpesh34 commented 4 years ago

How to return File object.

file = await imageCompression(file, imageOptions);
console.log(file instanceof File);//always false

i need this file as File Object

edsonfeimberg commented 4 years ago

Same here. imageCompression is always returning a blob

jiangyijie27 commented 4 years ago

@desaikalpesh34 @edsonfeimberg

If you want a File from a Blob, can simply do this:

const blob = await imageCompression(file, options)
const file = new File([compressedFile], "compressed.png")
Donaldcwl commented 4 years ago

For better browser compatibility, I decided to use Blob instead of File. e.g. Safari has an issue with File constructor not being able to POST in FormData e.g. Edge (Original) does not support File constructor see more in: https://github.com/Donaldcwl/browser-image-compression/blob/9fcc363eeec63c7ff044144cf98d5bb3a408201a/lib/utils.js#L55-L83

If you really need a File object for some reason, you can see the suggestion from @jiangyijie27.