nextcloud / nextcloud/nextcloudpi
Bug: HEIC files containing JPEG data cannot generate previews
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 2.9k
- Forks
- 318
- PR merge metrics
- No merged PRs in 30d
Description
Bug: HEIC files containing JPEG data cannot generate previews
Bug description
Nextcloud cannot generate previews for a number of files whose filename extension is .HEIC and whose Nextcloud MIME type is image/heic, but whose actual file content is JPEG.
The files appear to be JPEG images that were saved or renamed with a .HEIC extension.
For these files:
- Nextcloud reports the MIME type as
image/heic - ImageMagick detects the actual image format as
JPEG - PHP Imagick can successfully read the file as JPEG
occ preview:generatefails withNo provider successfully handled the preview generation- Renaming the file from
.HEICto.JPGusingocc files:moveimmediately allows preview generation - The file ID remains unchanged after the rename
This suggests that the HEIC preview provider is selected based on the Nextcloud MIME type, but the actual image data is JPEG and therefore cannot be processed correctly by the HEIC provider.
Environment
- Nextcloud Server: 34.x
- PHP: 8.5
- Web server: Apache
- OS: Debian
- MariaDB
- Raspberry Pi 5
- ImageMagick / Imagick installed
previewgenerator: 5.14.0memories: 8.1.0
The HEIC preview provider is explicitly enabled:
OC\Preview\Movie
OC\Preview\MP4
OC\Preview\MKV
OC\Preview\AVI
OC\Preview\Image
OC\Preview\HEIC
ImageMagick supports both HEIC and JPEG.
Example affected file
Original filename:
IMG_6886.HEIC
Nextcloud:
fileid: 283288
mimetype: image/heic
size: 480 KB
Actual file detection:
$ identify IMG_6886.HEIC
JPEG 4032x3024
The file command also identifies it as JPEG image data.
PHP Imagick can read it successfully:
READ OK
Format: JPEG
Size: 4032x3024
However:
$ php8.5 occ preview:generate "/admin/files/Photos/2020/01/IMG_6886.HEIC"
In Generator.php line 413:
No provider successfully handled the preview generation
Control test
I renamed the same file using Nextcloud:
occ files:move \
"/admin/files/Photos/2020/01/IMG_6886.HEIC" \
"/admin/files/Photos/2020/01/IMG_6886.JPG"
The same file then reports:
fileid: 283288
mimetype: image/jpeg
The file ID did not change.
After changing only the filename extension:
$ php8.5 occ preview:generate \
"/admin/files/Photos/2020/01/IMG_6886.JPG"
preview generated
The preview files were then created successfully, including:
48-64.jpg
3024-4032-max.jpg
This demonstrates that the underlying image data itself is valid and that ImageMagick/Imagick can process it.
Scale of the problem
I scanned the HEIC files in my Photos directory using ImageMagick.
There are:
2807 files detected as actual HEIC
1955 files detected as JPEG
The 1955 JPEG files all have .HEIC filenames.
For example:
/mnt/pool/nextcloud_data/admin/files/Photos/2020/01/IMG_6886.HEIC
/mnt/pool/nextcloud_data/admin/files/Photos/2020/01/IMG_6898.HEIC
/mnt/pool/nextcloud_data/admin/files/Photos/2020/01/IMG_6885.HEIC
...
Nextcloud still identifies these files as:
mimetype: image/heic
even though ImageMagick reports:
JPEG 4032x3024
Expected behavior
If a file has a .HEIC extension but its actual image data is JPEG, Nextcloud should ideally detect the actual image format and use an appropriate preview provider.
At minimum, the HEIC preview provider should fail gracefully and allow another compatible image preview provider to handle the file when the underlying image is actually JPEG.
Actual behavior
Nextcloud treats these files as image/heic and attempts to use the HEIC preview provider.
Preview generation fails:
No provider successfully handled the preview generation
Manually renaming the file to .JPG immediately fixes the problem.
Additional observation
A real HEIC file works correctly on the same system.
For example:
IMG_7125.HEIC
is detected by ImageMagick as:
HEIC 3024x4032
and:
occ preview:generate "/admin/files/Photos/2020/01/IMG_7125.HEIC"
returns:
preview generated
Therefore this does not appear to be a general ImageMagick/HEIC installation problem.
The problematic files specifically appear to be JPEG data stored under a .HEIC filename.
Reproduction
- Take a valid JPEG image.
- Rename it to
test.HEIC. - Upload it to Nextcloud.
- Nextcloud identifies it as
image/heic. - Confirm that ImageMagick identifies the actual data as JPEG.
- Run:
occ preview:generate "/path/to/test.HEIC"
- Preview generation fails.
- Rename the same file to
test.JPGusingocc files:move. - Run
occ preview:generateagain. - Preview generation succeeds.
Question
Could the HEIC preview provider fall back to the normal image/JPEG preview provider when the underlying file is actually JPEG?
Alternatively, could Nextcloud detect the actual image format before selecting the preview provider for files with a .HEIC extension?
I can provide additional logs, configuration, or test files if needed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documented occ preview:generate reproduction using a valid JPEG renamed to .HEIC, comparing it with a real HEIC file and the successful post-rename run. Trace how the HEIC preview provider is selected and verify that the affected file can generate previews without renaming while retaining its file ID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, shell
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100