Skip to content

Data Seeding: Create fake image data using image URLs #581

Answered by rayjasson98
rayjasson98 asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, calling model.image_attacher.set(image_data_hash) gave me this error:

bundle/gems/shrine-3.4.0/lib/shrine/attacher.rb:314:in `file=': expected file to be a Shrine::UploadedFile or nil, got ...

While digging into the source code, I found that I need to instantiate a Shrine::UploadedFile object with the image_data_hash. Also, I need a gem called shrine-url to create a fake storage that allows me to assign image data by custom URLs.

The full steps are shown below:

  1. Add gem "shrine-url", "~> 2.4" to your Gemfile.
  2. In your config/initializers/shrine.rb, add the following lines:
    require "shrine/storage/url"
    
    Shrine.storages = {
      test: Shrine::Storage::Url.new,
      ...
    }
  3. Create fake

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@rayjasson98
Comment options

Comment options

You must be logged in to vote
1 reply
@jrochkind
Comment options

Answer selected by rayjasson98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants