{"id":13879583,"url":"https://github.com/rootstrap/active-storage-base64","last_synced_at":"2025-11-11T18:39:35.818Z","repository":{"id":45292707,"uuid":"156597887","full_name":"rootstrap/active-storage-base64","owner":"rootstrap","description":"Base64 support for ActiveStorage","archived":false,"fork":false,"pushed_at":"2025-08-04T15:21:50.000Z","size":132,"stargazers_count":164,"open_issues_count":2,"forks_count":16,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-11-04T10:08:57.709Z","etag":null,"topics":["activestorage","api","hacktoberfest","rails","rails-api","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://rootstrap.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/rootstrap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-07T19:31:03.000Z","updated_at":"2025-09-04T15:32:36.000Z","dependencies_parsed_at":"2024-01-08T14:34:13.296Z","dependency_job_id":"a714d73d-7b6b-4c8c-9c40-fae7ef4c0ce3","html_url":"https://github.com/rootstrap/active-storage-base64","commit_stats":{"total_commits":70,"total_committers":14,"mean_commits":5.0,"dds":0.7285714285714286,"last_synced_commit":"ff00238b3d76773e00e3c7db8911359c1b987c1a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/rootstrap/active-storage-base64","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootstrap%2Factive-storage-base64","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootstrap%2Factive-storage-base64/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootstrap%2Factive-storage-base64/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootstrap%2Factive-storage-base64/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rootstrap","download_url":"https://codeload.github.com/rootstrap/active-storage-base64/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootstrap%2Factive-storage-base64/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283455221,"owners_count":26838720,"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-11-09T02:00:05.828Z","response_time":62,"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":["activestorage","api","hacktoberfest","rails","rails-api","ruby","ruby-on-rails"],"created_at":"2024-08-06T08:02:25.895Z","updated_at":"2025-11-11T18:39:35.797Z","avatar_url":"https://github.com/rootstrap.png","language":"Ruby","readme":"[![CI](https://github.com/rootstrap/active-storage-base64/actions/workflows/ci.yml/badge.svg)](https://github.com/rootstrap/active-storage-base64/actions/workflows/ci.yml)\n[![Maintainability](https://api.codeclimate.com/v1/badges/0da0a0901cedd72aeb10/maintainability)](https://codeclimate.com/github/rootstrap/active-storage-base64/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/0da0a0901cedd72aeb10/test_coverage)](https://codeclimate.com/github/rootstrap/active-storage-base64/test_coverage)\n\n# ActiveStorageBase64\n\nAdds support for base64 attachments to ActiveStorage.\n\n## Installation\n\nIn order to get the gem working on your project you just need to add the gem to your project like this:\n```ruby\ngem 'active_storage_base64'\n```\n\n## Compatibility\nRails Version | ActiveStorageBase64 Version\n--------------|-----------------------------\n8.1.x         | 3.0.x\n8.0.x         | 3.0.x\n7.2.x         | 3.0.x\n7.1.x         | 3.0.x\n7.0.x         | 2.0.x\n6.1.x         | 1.2.x\n6.0.x         | 1.1.x\n5.2.x         | 0.1.x\n\n## Prerequisites\n\nThe only prerequisite for using this gem is having ActiveStorage properly set up in your project. For more information on how to do this, check [Active Storage Overview](https://edgeguides.rubyonrails.org/active_storage_overview.html).\n\n## Usage\n\nIn order to use the gem's functionality, you need to include the `ActiveStorageSupport::SupportForBase64` module in your ActiveRecord models.\nFor example:\n```ruby\nclass User \u003c ActiveRecord::Base\n  include ActiveStorageSupport::SupportForBase64\nend\n```\n\nNote:\nWe highly recommend using an alternative class that inherits from `ActiveRecord::Base` and includes the module so instead of including the module for each of your classes, you make them inherit from this new class, check below:\n```ruby\nclass ApplicationRecord \u003c ActiveRecord::Base\n  include ActiveStorageSupport::SupportForBase64\nend\n\nclass User \u003c ApplicationRecord\n  has_one_base64_attached :avatar\nend\n```\n\nAfter you have the module included in your class you'll be able to use the following two helper methods to work with base64 files:\nWhen you need a single image attached:\n```ruby\nhas_one_base64_attached\n```\nand when you need multiple files attached:\n```ruby\nhas_many_base64_attached\n```\nThese helpers will work just like the `has_one_attached` and `has_many_attached` helper methods from ActiveStorage.\n\nA working example for this, assuming we have a model `User` with an `avatar` attached would be:\n```ruby\nclass User \u003c ActiveRecord::Base\n  include ActiveStorageSupport::SupportForBase64\n\n  has_one_base64_attached :avatar\nend\n```\n\non your controller you could do any of the following:\n```ruby\nclass UsersController \u003c ApplicationController\n  def create\n    user = User.create(user_params)\n  end\n\n  private\n\n  def user_params\n    params.require(:user).permit(avatar: :data, :username, :email)\n  end\nend\n```\n\n```ruby\nclass UsersController \u003c ApplicationController\n  def create\n    user = User.create(user_params)\n    user.avatar.attach(data: params[:avatar]) # params[:avatar] =\u003e 'data:image/png;base64,[base64 data]'\n  end\n\n  private\n\n  def user_params\n    params.require(:user).permit(:username, :email)\n  end\nend\n```\n\n```ruby\nclass UsersController \u003c ApplicationController\n  def create\n    user = User.create(user_params)\n    user.avatar.attach(avatar_params) # avatar_params =\u003e { data: 'data:image/png;base64,[base64 data]' }\n  end\n\n  private\n\n  def user_params\n    params.require(:user).permit(:username, :email)\n  end\n\n  def avatar_params\n    params.require(:avatar).permit(:data)\n  end\nend\n```\n\n```ruby\nclass UsersController \u003c ApplicationController\n  def create\n    user = User.create(user_params)\n    user.avatar = { data: params[:avatar] } # params[:avatar] =\u003e 'data:image/png;base64,[base64 data]'\n    user.save\n  end\n\n  private\n\n  def user_params\n    params.require(:user).permit(:username, :email)\n  end\nend\n```\n\n### Specifying a filename or content type\n\nIf you are willing to add a specific filename to your attachment, or send in a specific content type for your file, you can use `data:` to attach the base64 data and specify your `filename:`, `content_type:` and/or `identify:` hash keys.\nCheck the following example:\n```ruby\nclass UsersController \u003c ApplicationController\n  def create\n    user = User.create(user_params)\n    user.avatar.attach(data: params[:avatar], filename: 'your_filename', content_type: 'content/type', identify: 'false') # params[:avatar] =\u003e 'data:image/png;base64,[base64 data]'\n  end\n\n  private\n\n  def user_params\n    params.require(:user).permit(:username, :email)\n  end\nend\n```\n\nOr, in case you want to have the avatar attached as soon as the user is created you can do:\n```ruby\nclass UsersController \u003c ApplicationController\n  def create\n    user = User.create(user_params)\n  end\n\n  private\n\n  def user_params\n    params.require(:user).permit(:username, :email, avatar: [:data,\n                                                             :filename,\n                                                             :content_type,\n                                                             :identify])\n  end\nend\n```\n\n### Data Format\n\nTo attach base64 data it is required to come in the form of [Data URIs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) .\nFor example:\n```\ndata:image/png;base64,[base64 data]\n```\n\n### Avoid bloating logs\n\nBecause we use strings to pass data in params, if you are not careful, these long strings will show up in your production logs, causing a lot of bloat. To avoid this, filter your base64 params:\n```diff\n# config/initializers/filter_parameter_logging.rb\n\n- Rails.application.config.filter_parameters += [:password]\n+ Rails.application.config.filter_parameters += [:password, :avatar, :pictures, :file]\n```\n\n## Contributing\n\nPlease read our [CONTRIBUTING](https://github.com/rootstrap/active-storage-base64/blob/master/CONTRIBUTING.md) and our [CODE_OF_CONDUCT](https://github.com/rootstrap/active-storage-base64/blob/master/CODE_OF_CONDUCT.md) files for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Author\n\n*Ricardo Cortio*\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/rootstrap/active-storage-base64/blob/master/LICENSE.txt) file for details\n\n## Acknowledgments\n\nSpecial thanks to the people who helped with guidance and ensuring code quality in this project:\n*Santiago Bartesaghi, Santiago Vidal and Matias Mansilla.*\n\n## Credits\n\nActive Storage Base64 is maintained by [Rootstrap](http://www.rootstrap.com) with the help of our\n[contributors](https://github.com/rootstrap/active-storage-base64/contributors).\n\n[\u003cimg src=\"https://s3-us-west-1.amazonaws.com/rootstrap.com/img/rs.png\" width=\"100\"/\u003e](http://www.rootstrap.com)\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootstrap%2Factive-storage-base64","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frootstrap%2Factive-storage-base64","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootstrap%2Factive-storage-base64/lists"}