How to upload and convert HEIC/HEIF in applications without identifying file types?

Is there any library available that would allow me to upload both HEIC and HEIF photos, or at least convert them to another format for preview purposes?

I am currently using the file upload component from Ant Design (antd) in my project. Additionally, I’m utilizing the heic2any library to convert HEIC files to JPG, and it works well for its intended purpose. Here is the code I’m using:

const handleChange = (info) => {
    // Code to handle file upload and conversion

My problem arises when I encounter a HEIF file. The heic2any library doesn’t support HEIF format; it only handles HEIC files. Moreover, I’m unable to determine the file type during upload, as both HEIF and HEIC files do not seem to have a recognizable type attribute in their data when uploaded. This lack of file type recognition makes it difficult to validate and process these files correctly.

1 Like

The challenge you are facing with identifying and processing HEIF files is understandable, given that heic2any focuses on HEIC. For handling both HEIC and HEIF formats, you might need a more versatile library or a combination of tools.

One approach is to use a server-side solution for file conversion. Libraries like ImageMagick or FFmpeg have broader format support and can handle both HEIC and HEIF files. You can upload the files to your server and then use these libraries to convert them to a more common format like JPG for preview purposes.

How would I implement this server-side solution, especially since I can’t identify the file type on upload?

On the server side, you can rely on the file’s MIME type or content to determine its format. Tools like ImageMagick and FFmpeg are capable of reading the file’s binary data to accurately identify and process it, regardless of its extension or MIME type provided by the client.

For the client side, you might still want to implement some form of validation or fallback. If a file does not have a recognized type, you could assume it might be HEIC or HEIF and send it to the server for verification and processing.