MahmoudMabrouk(mo3ta)
2 min readMar 21, 2020

Get Extension From URI android

I have a Task to upload file to S3 using presigned URL, I create an atomic name from current date and want extension to append it and send it to S3 but faced problems to get extensions and here will share journey

Let’s start

we can get it in two ways

  • Get Path and got extension as it last part.
  • Get MIME Type

First way: Path

code to get path

this will return path and use this filePath.substring(filePath.lastIndexOf(".") + 1);

but previous call may return null in case of file is stored in google photos (i.e. not locally on phone) so we must download it into device (which add more space on device) and then get path

Second: MIME Type

this way is guarantee to get extension but as Type which treat JPEG/JPG as JPEG

I hope this help you when dealing with this task.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

MahmoudMabrouk(mo3ta)
MahmoudMabrouk(mo3ta)

No responses yet

Write a response