A simple rails application with an API and a simple web interface to upload & host static files (Images, Fonts) or any other files with Google Firebase for free (refer limits).
-
Create a firebase project - Firebase Console.
-
Create a default storage bucket
- Click Develop > Storage > Get Started > Next > Choose Location > Done
-
Download the credentials json file with private key from firebase console.
- Click Settings Icon > Project Settings > Service Accounts > Generate new private key > Generate key
-
Clone this repository
git clone https://github.com/owaiswiz/devitary.git
-
Set the environment variable
STORAGE_CREDENTIALS
with the content of the downloaded json file -
Run the server using
rails s
or deploy how you would deploy any other rails app
Create a post request to /upload
with the file in the multipart form data body
response = HTTParty.post(
'http://YOURHOSTEDIPORURL/upload',
body: {
file: File.open("/home/owaiswiz/Downloads/SashaSloan.png")
}
)
json = JSON.parse(response.body)
puts json["url"] # => "https://storage.googleapis.com/devitary-image-host.appspot.com/15828387941719051810-c.png"