Skip to content

fix SVG file processing and upload validation#6665

Open
Roniscend wants to merge 1 commit intocommons-app:mainfrom
Roniscend:fix_svg_files
Open

fix SVG file processing and upload validation#6665
Roniscend wants to merge 1 commit intocommons-app:mainfrom
Roniscend:fix_svg_files

Conversation

@Roniscend
Copy link
Contributor

@Roniscend Roniscend commented Feb 22, 2026

Description (required)
I updated the upload flow to properly handle .svg files by integrating SVG decoding logic, which was previously causing thumbnails to appear as black screens. By ensuring the app correctly recognizes and renders SVG vector data into a visible Drawable, users can now preview their files before uploading.
Fixes #6650

What changes did you make and why?
I integrated SVG decoding logic into the upload flow to properly handle .svg files, which previously caused thumbnails to appear as black screens. Users can now accurately verify their SVG files on their devices before completing an upload.

Tests performed (required)

Tested 6.3.0-debug on a Pixel 9 running Android 16 (API 36)

Screenshots (for UI changes only)

Solution.mp4

Copilot AI review requested due to automatic review settings February 22, 2026 14:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Android Commons upload UI to correctly preview SVG files by adding SVG rendering support (AndroidSVG) and adjusting upload/edit behaviors so SVGs no longer appear as black thumbnails during the upload flow. This addresses the SVG preview portion of issue #6650.

Changes:

  • Added AndroidSVG dependency and introduced SvgUtils to detect and render SVGs to bitmaps/drawables.
  • Updated upload thumbnail and media detail screens to render SVGs via SvgUtils and hide the “Edit image” action for SVGs.
  • Skipped the “image too dark” check for SVG inputs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
gradle/libs.versions.toml Adds version + library entry for AndroidSVG.
app/build.gradle.kts Includes AndroidSVG dependency in the app module.
app/src/main/java/fr/free/nrw/commons/utils/SvgUtils.kt New utility for SVG detection and rendering to Bitmap/Drawable.
app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.kt Bypasses darkness check for SVG inputs.
app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt Renders SVG previews on the media detail screen; hides edit UI for SVG.
app/src/main/java/fr/free/nrw/commons/upload/ThumbnailsAdapter.kt Renders SVG thumbnails in the upload thumbnails list.
app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt Blocks editing for SVGs (exits early with a toast).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Roniscend Roniscend force-pushed the fix_svg_files branch 2 times, most recently from 710c888 to 351dce9 Compare February 22, 2026 15:54

if (isMediaSvg || isFileSvg) {
viewLifecycleOwner.lifecycleScope.launch {
val drawable = withContext(Dispatchers.IO) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need IO thread to render image?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owm would you mind addressing the unresolved comments? Thanks!

val uploadableFile = uploadableFiles[position]
val uri = uploadableFile.getMediaUri()
background.setImageURI(Uri.fromFile(File(uri.toString())))
val filePath = uploadableFile.getFilePath()?.toString() ?: ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a if(filepath.isNullOrBlank.not())

org.gradle.jvmargs=-Xmx1536M
org.gradle.caching=true
android.enableR8.fullMode=false

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove anything unrelated to this change so it doesn’t show up in the git diff? It will help keep the review clean and focused.

}

if (imageUri.substringBefore("?").endsWith(".svg", ignoreCase = true)) {
Toast.makeText(this, "SVG files cannot be edited", Toast.LENGTH_SHORT).show()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will review this today, thanks for contributing @Roniscend. Can I know is there any reason we can't edit svg images?

Copy link
Collaborator

@Kota-Jagadeesh Kota-Jagadeesh Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I know is there any reason we can't edit svg images?

@neeldoshii Not sure but based on one of the issues I’m working on, the reason might be that SVG files don’t contain EXIF headers, which could be causing the problem :)

Comment link : #6642 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, our current editing flow relies on EXIF metadata, which svg do not have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app exists because smartphones have become the main way people take pictures. By contrast, creating SVG on smartphone is an extremely niche use case. In my experience monitoring the app's uploads, most non-photography files uploaded from the app are copyright violations. So I think it makes sense to focus our limited resources on photography formats. 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case how about we convert svg to png first? Not sure if its possible or not and how much workaround is there will check it once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have the bandwidth to maintain any SVG or PNG editing features.

We can grey out the edit button and when tapped, it could say something like "To edit non-JPG files, use third-party tools".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can grey out the edit button

@nicolas-raoul this was recently fixed in #6653 as part of #6642 ,and now the edit image button will be disabled for the non JPG files :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one sounds better actually. It's more transparent for our users, otherwise they'll keep wondering when that Edit button appears. I'll create a follow-up issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"To edit non-JPG files, use third-party tools".

Great. Also just an idea for suggestion not sure it good or not. How about we provide third party tool link and user can click and go to the website (externally, in app is very hard to maintain as we don't know when to close) and once the user has converted the image to jpg, user can finally upload jpg image.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind letting us know what is the apk file size before and after this PR?

@nicolas-raoul
Copy link
Member

Would you mind rebasing from main?

Signed-off-by: Owm Dubey <owmdubey163@gmail.com>

# Conflicts:
#	app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt

# Conflicts:
#	app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt
#	app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

✅ Generated APK variants!

@Roniscend
Copy link
Contributor Author

Would you mind letting us know what is the apk file size before and after this PR?

This branch increases the application size by approximately 0.4 MB

@neeldoshii
Copy link
Collaborator

neeldoshii commented Mar 18, 2026

This branch increases the application size by approximately 0.4 MB

on which build flavour? was proguard enabled on that? I think 0.4 MB won't be a big tradeoff if we remove fresco as removing fresco will reduce the app size in long run, also is the PR ready to review?

newViewHeight = (drawableHeight * newImageScale).toInt()
}
else -> {
throw
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add catch instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: .SVG files are not displayed

6 participants