Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

carrierwave-data

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

carrierwave-data

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

CarrierWave::Data

Allows CarrierWave to process Base64 encoded file uploads.

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-data'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-data

Usage

Assuming you have a User model with a UserAvatarUploader mounted on an avatar attribute.

class User < ActiveRecord::Base
  mount_uploader :avatar, UserAvatarUploader
end

A User's avatar can be set using a Base64 encoded string, as follows.

user = User.new
user.avatar_data = {
  data: 'iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABuBvAAAABGdBTUE...kJggg==',
  name: 'avatar',
  ext:  'jpg'
}
## or
# user.avatar_data = 'iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABuBvAAAABGdBTUE...kJggg=='
user.save
    
user.avatar? # => true
user.avatar  # => #<UserAvatarUploader:0x007f9575fddc18 @model=#<User id: 1, avatar: "...">, @mounted_as=:avatar, ...>

Customizations

By default, the filename of the decoded uploaded file is set to a random hex string, using SecureRandom.hex. To customize this behaviour, override the decoded_#{mounted_as}_filename method on your model.

class User < ActiveRecord::Base
  mount_uploader :avatar, UserAvatarUploader
  
  def decoded_avatar_filename
    'avatar'
  end
end

You can also customize the extension of the decoded uploaded file by overriding the decoded_#{mounted_as}_extension method. By default, no extension is set.

class User < ActiveRecord::Base
  mount_uploader :avatar, UserAvatarUploader
    
  def decoded_avatar_extension
    :png
  end
end

Contributing

  1. Fork it ( https://github.com/RaMin0/carrierwave-data/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

FAQs

Package last updated on 25 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc