Skip to content

fix: Update MIME type handling in CustomWebChromeClient#178

Open
mkusnierz wants to merge 1 commit into
Moustachauve:devfrom
mkusnierz:fix/file-picker-files-grayed-out
Open

fix: Update MIME type handling in CustomWebChromeClient#178
mkusnierz wants to merge 1 commit into
Moustachauve:devfrom
mkusnierz:fix/file-picker-files-grayed-out

Conversation

@mkusnierz
Copy link
Copy Markdown

Note

Implemented by Copilot. I tested it on my phone.

Fixes #141

Previously it was loading a generic file picker with all files grayed out.
Now it directly opens image picker in "Image Tool" and file picker in "Software Update" (that accepts any file type).


Summary

  • Fixed file picker showing all files as grayed out when uploading files through the WLED web UI
  • getMimeType() now passes through any value already in type/subtype format (e.g. image/*, image/jpeg) directly to the file picker intent
  • Changed the fallback MIME type from application/octet-stream to */* so that all files are selectable when no specific type is recognised

Motivation

WLED's web UI uses a standard HTML <input type="file" accept="image/*"> element for image uploads. When this triggers the Android file chooser, the browser passes the accept attribute value (e.g. image/*) as-is in FileChooserParams.acceptTypes.

getMimeType() only handled two specific file extensions (.jsonapplication/json, .csstext/css). Any other value — including valid MIME types like image/* — fell through the when expression and returned the hardcoded fallback application/octet-stream.

Intent.ACTION_GET_CONTENT uses the intent type to filter which files the user can select. When the type is application/octet-stream, the file picker renders images (and most other files) as grayed-out and non-selectable, because their actual MIME types do not match.

The fix recognises that any string containing / is already a valid MIME type and forwards it directly to the intent, so image/* correctly enables image selection. The fallback is also relaxed to */* to keep all files accessible when the accept type is unknown.

How to Test

  1. Open the app and navigate to a WLED device.
  2. In the device's web UI, go to PixelForge → Image Tool (or any page with a file upload input).
  3. Tap the file upload button that expects an image.
  4. Verify the system file picker opens and image files are selectable (not grayed out).
  5. Select an image and confirm it uploads successfully.

@github-actions github-actions Bot added the bug Something isn't working label May 19, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the getMimeType function in DeviceWebview.kt to improve MIME type detection, specifically by allowing types that already contain a slash and changing the default fallback to /. A review comment suggests utilizing android.webkit.MimeTypeMap to handle a broader range of file extensions dynamically and highlights a potential limitation where only the first valid MIME type is returned, which may restrict file selection when multiple types are requested.

Comment on lines +392 to 397
return when {
type == ".json" -> "application/json"
type == ".css" -> "text/css"
type.contains("/") -> type
else -> continue
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Instead of hardcoding specific extensions like .json and .css, you can use android.webkit.MimeTypeMap to support a wider range of file types.

Also, note that this logic returns the first valid MIME type found and ignores any subsequent ones. If a web page specifies multiple types (e.g., accept="image/*, application/pdf"), the file picker will be restricted to only the first type, preventing the user from selecting others. For a more robust implementation, consider handling multiple MIME types or falling back to */* when more than one type is provided.

Suggested change
return when {
type == ".json" -> "application/json"
type == ".css" -> "text/css"
type.contains("/") -> type
else -> continue
}
return when {
type.startsWith(".") -> android.webkit.MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(type.substring(1)) ?: continue
type.contains("/") -> type
else -> continue
}

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant