Repository navigation
Resolve file URIs through ContentResolver so Storage putFile(Uri) works - #84
Merged
Merged
Conversation
Firebase Storage's putFile(Uri) opens the file through ContentResolver.openFileDescriptor to learn its size and then reads it through openInputStream, and uses getType for the content type when the metadata has none. The ContentResolver shim was empty, so putFile(Uri) failed on the JVM with a NoSuchMethodError. ContentResolver now resolves file: URIs (and bare paths) to files, backed by a new ParcelFileDescriptor shim over a RandomAccessFile with the Android mode flags, and guesses the MIME type from the file name. Other schemes are reported as not found, as there are no content providers on the JVM.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues include a missing adoptFd API that breaks Java compilation and file-mode handling that can truncate data, violate access restrictions, or overwrite interleaved append writes.
4 open issues
What changed in this PR
This PR adds JVM file access to the Android ContentResolver shim so Firebase Storage’s putFile(Uri) can read file sizes, contents, and inferred MIME types.
Changes:
- Replaces the empty Java resolver with a Kotlin implementation supporting file URIs and bare paths.
- Adds a
ParcelFileDescriptorshim with file-size reporting and Android mode flags. - Adds tests for URI formats, streams, write modes, MIME types, and missing files.
| File | Description |
|---|---|
src/test/kotlin/ContentResolverTest.kt |
Adds coverage for resolver and descriptor behavior. |
src/main/java/android/os/ParcelFileDescriptor.kt |
Adds file-backed descriptors and mode parsing. |
src/main/java/android/content/ContentResolver.kt |
Implements file resolution, stream access, and MIME inference. |
src/main/java/android/content/ContentResolver.java |
Removes the empty shim replaced by Kotlin. |
Review effort: Balanced
Read-only descriptors are backed by a FileInputStream, write-only ones by a FileOutputStream that truncates or appends (so concurrent "wa" descriptors interleave at the end of the file), and read-write ones by a RandomAccessFile that no longer truncates for "rw". openOutputStream rejects read-only modes and writes in place for "rw". adoptFd is declared and unsupported, matching the SQLite shim's reference.
This was referenced Nov 9, 2026
Merged
nbransby
added a commit
to GitLiveApp/firebase-kotlin-sdk
that referenced
this pull request
Nov 9, 2026
firebase-java-sdk 0.8.1 implements `ContentResolver.openFileDescriptor` and the file-backed `ContentResolver` streams (GitLiveApp/firebase-java-sdk#84), so Firebase Storage's `putFile(Uri)` now works on the JVM. The JVM `supportsFileUploads` test gate added in #889 for that gap is removed, so the storage upload test runs on the JVM as well. All 25 storage JVM tests pass locally against the published 0.8.1 artifact and the Storage emulator, the upload test included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Firebase Storage's
putFile(Uri)opens the file throughContentResolver.openFileDescriptorto learn its size, reads it throughopenInputStream, and asksgetTypefor the content type when the metadata has none. Theandroid.content.ContentResolvershim was an empty class, so on the JVMputFile(Uri)failed withNoSuchMethodError: ContentResolver.openFileDescriptor.ContentResolvernow resolvesfile:URIs (and bare paths) to files:openFileDescriptor,openInputStream,openOutputStream(with thew/wt/wa/rw/rwtmodes) andgetType, which guesses the MIME type from the file name. Other schemes are reported asFileNotFoundException, since there are no content providers on the JVM. A newandroid.os.ParcelFileDescriptorshim backs it, holding aRandomAccessFilewith the AndroidMODE_*flags andparseMode.ContentResolverTestcovers the size reported through the descriptor forfile:/,file:///and bare-path URIs, reading and writing streams, append and truncate modes, the type guess, and the not-found cases.Verified end to end against the Storage emulator with the firebase-kotlin-sdk storage tests on the JVM: with this jar,
putFile(Uri)of a downloaded file uploads it with the right size.