element-hq / element-hq/element-x-android

Unable to save image/file if there are 32 file name conflicts, "Sorry, an error occured" (Unable to save any file named image.png anymore)

Open
#6,371 1 comment 0 reactions 0 assignees View on GitHub
O-Uncommon S-Major T-Defect
Dominant language
Kotlin
Stars
2.4k
Forks
624
Avg merge
1d 14h
Merged PRs (30d)
149

Description

### Steps to reproduce

Pick any image in a chat and save it 32 times, then try saving it again.

### Outcome

#### What did you expect?

I should be able to save an indefinite number of files with the same name

#### What happened instead?

After saving the same filename 32 times I am not able to save any file with the same name (even if it's a different file) because the file name already exists with suffixes going all the way up to (31).

This is huge problem because a lot of images have the same name such as image.png and I am not able to save any of those images anymore because I already have image.png, image (1).png, ..., image (31).png in my Download folder, and I guess the loop that tries different filenames gives up after 32 attempts.

Image

Image

Image

Error from log:

```
2026-03-17T20:01:13.675634Z ERROR elementx: Save on disk failed
java.lang.IllegalStateException: Failed to build unique file: /storage/emulated/0/Download/image.png owner_package_name=io.element.android.x _display_name=image.png mime_type=image/png _data=/storage/emulated/0/Download/image.png is_download=1 relative_path=Download/
at android.os.Parcel.createExceptionOrNull(Parcel.java:3378)
at android.os.Parcel.createException(Parcel.java:3354)
at android.os.Parcel.readException(Parcel.java:3337)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:225)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:177)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:591)
at android.content.ContentResolver.insert(ContentResolver.java:2282)
at android.content.ContentResolver.insert(ContentResolver.java:2243)
at io.element.android.libraries.mediaviewer.impl.local.AndroidLocalMediaActions.access$saveOnDiskUsingMediaStore(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:41)
at io.element.android.libraries.matrix.impl.RustMatrixClient$findDM$2.invokeSuspend(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:269)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:9)
at kotlinx.coroutines.DispatchedTask.run(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:115)
at com.google.android.gms.tasks.zzc.run$kotlinx$coroutines$internal$LimitedDispatcher$Worker(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:6)
at com.google.android.gms.tasks.zzc.run(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:45)
at kotlinx.coroutines.scheduling.TaskImpl.run(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:3)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(r8-map-id-61ec08b4fbd12f33364cb071e26815858d814832c3e7576695ecebb2cf1a3240:88)
|
```

### Your phone model

Pixel 6 Pro

### Operating system version

Android 16

### Application version and app store

26.03.3

### Homeserver

matrix.org

### Will you send logs?

Yes

### Are you willing to provide a PR?

No

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.