Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get file extension from URI for an rails application

I want to find File extensions like .gif,.jpg,.txt from the uri like http://testasp.vulnweb.com/avatars/noavatar.gif.

like image 503
Nidhi Barot Avatar asked Jan 06 '12 10:01

Nidhi Barot


People also ask

Is there any way to get the file extension from a URL?

GetFileName() and Path. GetExtension() methods to get the file name and file type (or extension) of a given URL.

How do I get the file extension in Ruby?

extname() or extname() function of the File class in Ruby gets the extension of a file. For example, this function will return the extension of a Ruby application file main. rb as . rb .


1 Answers

You can use an extname method of File

url = "http://testasp.vulnweb.com/avatars/noavatar.gif"
File.extname(url) #=> .gif
like image 102
alony Avatar answered Oct 05 '22 04:10

alony