I think you want lastIndexOf, because this will behave unexpectedly if you have a `.` in the file name like `a.b.jpg`.

It might be better to attach the extension based on the content type attribute of the image. Just rely on what the browser says, you know?