firebase-android-sdk: putFile(Uri) failed : UploadTask: could not retrieve file size for upload android.resource://com.package.name/drawable/ic_drawable

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general Firebase discussion, use the firebase-talk google group.
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: _____
  • Firebase Component: 20.0.0 (Database, Firestore, Storage, Functions, etc)
  • Component version: _____

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

Relevant Code:

val uploadUri = mProfilePicURI ?: Uri.Builder()
                                .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
                                .authority(resources.getResourcePackageName(R.drawable.ic_user))
                                .appendPath(resources.getResourceTypeName(R.drawable.ic_user))
                                .appendPath(resources.getResourceEntryName(R.drawable.ic_user))
                                .build()
W/UploadTask: could not retrieve file size for upload android.resource://com.myapp.sample/drawable/ic_user
    java.io.FileNotFoundException: Resource does not exist: android.resource://com.myapp.sample/drawable/ic_user

The Uri coming from drawable resource is not working while Uri from file manager, gallery, camera return by ActivityResult works fine such as file:///data/data/com.sample.app/cache/cropped-1168776960.jpg.

What could be the reason behind this? I can use the Uri.Builder value to imagVeiew.setImageUri(uriBuild) so the expectation of it working is reasonable.

Is there a specific format when using Uri? Thanks.

Note: Uploading works successfully despite the issue but the file itself which in this case is an image is not valid file that cannot be viewed or download.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Yes, I’ve checked correct file and valid image. Perhaps you could provide us an MCVE, so we can investigate this deeper.