{"id":13880284,"url":"https://github.com/transloadit/rails-sdk","last_synced_at":"2025-10-09T20:11:54.874Z","repository":{"id":689279,"uuid":"1422169","full_name":"transloadit/rails-sdk","owner":"transloadit","description":"Transloadit's official Rails SDK, maintained by the community","archived":false,"fork":false,"pushed_at":"2023-03-24T18:40:48.000Z","size":142,"stargazers_count":47,"open_issues_count":0,"forks_count":21,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-09-22T22:58:30.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://transloadit.com/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/transloadit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-02-28T16:20:55.000Z","updated_at":"2023-11-03T18:40:51.000Z","dependencies_parsed_at":"2023-07-06T21:01:18.487Z","dependency_job_id":null,"html_url":"https://github.com/transloadit/rails-sdk","commit_stats":{"total_commits":163,"total_committers":20,"mean_commits":8.15,"dds":0.558282208588957,"last_synced_commit":"4283e5d1ae335e79723c39d9a4a3a9d2af00d03c"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/transloadit/rails-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transloadit%2Frails-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transloadit%2Frails-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transloadit%2Frails-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transloadit%2Frails-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/transloadit","download_url":"https://codeload.github.com/transloadit/rails-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transloadit%2Frails-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002017,"owners_count":26083258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:02:54.942Z","updated_at":"2025-10-09T20:11:54.842Z","avatar_url":"https://github.com/transloadit.png","language":"Ruby","funding_links":[],"categories":["Ruby","Gems"],"sub_categories":["Articles"],"readme":"[![CI](https://github.com/transloadit/rails-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/transloadit/rails-sdk/actions/workflows/ci.yml)\n\n## rails-sdk\n\nA **Rails** Integration for [Transloadit](https://transloadit.com)'s file uploading and encoding service\n\n## Intro\n\n[Transloadit](https://transloadit.com) is a service that helps you handle file uploads, resize, crop and watermark your images, make GIFs, transcode your videos, extract thumbnails, generate audio waveforms, and so much more. In short, [Transloadit](https://transloadit.com) is the Swiss Army Knife for your files.\n\nThis is a **Rails** SDK to make it easy to talk to the [Transloadit](https://transloadit.com) REST API.\n\n*This gem provides browser integration. If you're looking to integrate Transloadit from your own serverside Ruby code checkout the [ruby-sdk](https://github.com/transloadit/ruby-sdk).*\n\n## Install\n\n```bash\n$ gem install transloadit-rails\n```\n\nor add the `transloadit-rails` Gem to your Rails project's `Gemfile` and update your bundle.\n\n```bash\n$ echo \"gem 'transloadit-rails'\" \u003e\u003e Gemfile\n$ bundle install\n```\n\nAfter installation you need to run the `transloadit:install` generator to complete the setup.\n\n```bash\n$ rails g transloadit:install\n```\n\n## Configuration\n\nEdit `config/transloadit.yml`. It has an `auth` section for your transloadit\ncredentials and a `templates` section to define or refer to existing\ntemplates. It is highly recommended to [enable authentication](https://transloadit.com/docs/authentication) and signing for\nthe upload forms.\n\n```yaml\nauth:\n  key     : 'TRANSLOADIT_KEY'\n  secret  : 'TRANSLOADIT_SECRET' # optional, but highly recommended\n  duration: 1800      # 30 minute validity period for signed upload forms\n\ntemplates:\n  # template identified by template_id\n  s3_store: 'YOUR_TEMPLATE_ID'\n\n  # template defined inline\n  image_resize:\n    steps:\n      resize:\n        robot : '/image/resize'\n        width : 320\n        height: 200\n```\n\n### Configuration by Environment\n\nThe transloadit configurations can be further broken up by environment tags to\nmatch the environments used by the application (i.e.  development, test,\nproduction).\n\nPlease note, the environment tags must match the application's environments\nexactly in order to be used.\n\n```yaml\ndevelopment:\n  auth:\n    key     : 'TRANSLOADIT_KEY'\n    ...\n\n  templates:\n    s3_store: 'YOUR_TEMPLATE_ID'\n    ...\n\nproduction:\n  auth:\n    key     : 'TRANSLOADIT_KEY'\n    ...\n\n  templates:\n    s3_store: 'YOUR_TEMPLATE_ID'\n    ...\n```\n\n## Usage\n\nRefer to the \u003cdfn\u003eTemplates\u003c/dfn\u003e (which you have set in the [config](https://github.com/transloadit/rails-sdk/#configuration)) with the `transloadit` helper.\n\n```erb\n\u003c%= form_for :upload, :html =\u003e { :id =\u003e 'upload' } do |form| %\u003e\n  \u003c%= transloadit :s3_store %\u003e\n  \u003c%= form.label      :file, 'File to upload' %\u003e\n  \u003c%= form.file_field :file %\u003e\n  \u003c%= form.submit %\u003e\n\u003c% end %\u003e\n\n\u003c%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' %\u003e\n\u003c%= transloadit_jquerify :upload %\u003e\n```\n\nThis requires jQuery, and loads the [Transloadit jQuery plugin](https://github.com/transloadit/jquery-sdk/). Be sure to exclude the `\u003c%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' %\u003e` tag if you already have jQuery loaded.\n\nJavaScript also ensures your form is encoded as `multipart/form-data`.\n\nIf you want to use the automatic `transloadit` parameter decoding, you have to include\nthe `Transloadit::Rails::ParamsDecoder` module into your controller\n\n```ruby\nclass YourController\n  include Transloadit::Rails::ParamsDecoder\nend\n```\n\nThat way the `param[:transloadit]` is automatically decoded for you, if it exists.\n\n\u003cdiv class=\"alert alert-note\"\u003e\n  \u003cstrong\u003eNote:\u003c/strong\u003e Since it's still very young, the Transloadit Rails SDK does not include batteries for it yet, but\n  if you're looking for a jQuery-less integration, check out \u003ca href=\"https://transloadit.com/docs/sdks/uppy/\"\u003eUppy\u003c/a\u003e, our next-gen file uploader for the web.\n\u003c/div\u003e\n\n## Tutorial\n\nIn this tutorial, you are going to learn how to use transloadit in a freshly\nsetup rails project.\n\nIf you haven't already done so, go ahead and install Rails.\n\n```bash\n$ gem install rails\n```\n\nWith rails installed, let's create a new app called 'my_app'.\n\n```bash\n$ rails new my_app\n$ cd my_app\n```\n\nIn order to use transloadit in this app, we need to add the gem to our Gemfile\nand bundle things up.\n\n```bash\n$ echo \"gem 'transloadit-rails'\" \u003e\u003e Gemfile\n$ bundle install\n```\n\nWith that in place, it's time to generate our transloadit configuration, as\nwell as a basic UploadsController and a dummy Upload model.\n\n```bash\n$ rails g transloadit:install\n$ rails g controller uploads new create\n$ rails g model upload\n$ rake  db:migrate\n```\n\nThe controller generator we just executed has probably put two GET routes into\nyour `config/routes.rb`. We don't want those, so lets go ahead an overwrite\nthem with this.\n\n```ruby\nMyApp::Application.routes.draw do\n  resources :uploads\nend\n```\n\nNext we need to configure our `config/transloadit.yml` file. For this tutorial,\njust put in your credentials, and define an image resize step as indicated\nbelow:\n\n```yaml\nauth:\n  key     : '4d2e...'\n  secret  : '8ad1...'\n  duration: 1800      # 30 minute validity period for signed upload forms\n\ntemplates:\n  image_resize:\n    steps:\n      resize:\n        robot : '/image/resize'\n        format: 'jpg'\n        width : 320\n        height: 200\n```\n\nNote that we encourage you to enable authentication in your Transloadit Account\nand put your secret into the ```config/transloadit.yml``` to have your requests\nsigned.\n\nAlright, time to create our upload form. In order to do that, please open\n`app/views/uploads/new.html.erb`, and put the following code in:\n\n```erb\n\u003c%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' %\u003e\n\n\u003ch1\u003eUpload an image\u003c/h1\u003e\n\u003c%= form_for Upload.new, :html =\u003e { :id =\u003e 'upload' } do |form| %\u003e\n  \u003c%= transloadit :image_resize %\u003e\n  \u003c%= form.label      :file, 'File to upload' %\u003e\n  \u003c%= form.file_field :file %\u003e\n  \u003c%= form.submit %\u003e\n\u003c% end %\u003e\n\n\u003c%= transloadit_jquerify :upload, :wait =\u003e true %\u003e\n```\n\nWith this in place, we can modify the `app/views/uploads/create.html.erb` view\nto render the uploaded and resized image:\n\n```erb\n\u003ch1\u003eResized upload image\u003c/h1\u003e\n\u003c%= image_tag params[:transloadit][:results][:resize].first[:url] %\u003e\n```\n\nIn order to use the transloadit params in your controller and views you\nhave to include the ParamsDecoder into your controller. Let's do that for our\nUploadsController.\n\nOpen up `app/controllers/uploads_controller.rb` and adapt it like that:\n\n```ruby\nclass UploadsController \u003c ApplicationController\n  include Transloadit::Rails::ParamsDecoder\n\n  def new\n  end\n\n  def create\n  end\n\nend\n```\n\nThat's it. If you've followed the steps closely, you should now be able to\ntry your first upload. Don't forget do start your rails server first:\n\n```bash\n$ rails server\n```\n\nThen go to http://localhost:3000/uploads/new, and upload an image. If you did\neverything right, you should see the uploaded and resized file as soon as the\nupload finishes.\n\n## Example\n\nAn example rails application following the [tutorial above](https://github.com/transloadit/rails-sdk/#tutorial) can be found in the [examples](https://github.com/transloadit/rails-sdk/tree/master/examples) directory.\n\n## Testing\n\n### RSpec request specs\n\nIf you want to test your file uploads without relying on the network (a\ngood idea to keep them fast and lean) you can include some request spec\nhelpers to allow you to easily populate the `transloadit_params` and\n`params[:transloadit]` in your actions.\n\nFirst, in your `spec/spec_helper.rb` :\n```ruby\nrequire 'transloadit/rspec/helpers'\n```\n\nNow, in your request spec :\n```ruby\n# NOTE: It's important that you don't use :js =\u003e true, otherwise your\n#       test will actually hit out using AJAX, making your test dependent on the\n#       network.\nit \"can upload data files\", :js =\u003e false do\n  attach_file 'upload_file', Rails.root.join('spec', 'asset', 'example.pdf')\n\n  # UploadsController should be replaced with the actual controller\n  # you're expecting to POST to when the upload is done\n  stub_transloadit!(UploadsController, example_json)\n\n  click_button 'Submit'\nend\n\ndef example_json\n  \"{ ... JSON content from a real POST ... }\"\nend\n```\n\n## Compatibility\n\nAt a minimum, this gem should work on MRI 2.3.0, 2.2.0, 2.1.0, Rubinius, and JRuby.\nIt may also work on older ruby versions, but support for those Rubies is not guaranteed.\nIf it doesn't work on one of the officially supported Rubies, please file a bug report.\nCompatibility patches for other Rubies are welcome.\n\nSupport for EOL'd Ruby 1.9.x and Ruby 2.0 has been dropped, please use version 1.2.0\nif you need support for older Ruby versions.\n\nTesting against these versions is performed automatically by [GitHub Actions](https://github.com/transloadit/rails-sdk/actions/workflows/ci.yml).\n\n### Support IE6 or jQuery \u003c 1.9\n\nIf you have to support IE6 and use a jQuery version below 1.9, you have to change\nthe jquery_sdk_version in the config to 'v1.0.0':\n\n```yaml\nproduction:\n  jquery_sdk_version: 'v1.0.0'\n  auth:\n    ...\n```\n\n## License\n\nMIT, see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftransloadit%2Frails-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftransloadit%2Frails-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftransloadit%2Frails-sdk/lists"}