Skip to content

ActiveStorage::FileNotFoundError in before_save #36994

@franktisellano

Description

@franktisellano

Steps to reproduce

Example Repo

Background

I'm using Active Storage with Disk storage. I want users to upload a json file attached to a model called Test_Model. The model has an attribute name that I'd like to populate with data from the JSON file.

When I call JSON.parse(self.jsonfile.download) to retrieve the name from the json file, I get an ActiveStorage::FileNotFoundError error.

Steps

  1. Clone the Example Repo
  2. bundle && rails db:migrate
  3. Visit http://localhost:3000/test_models/new
  4. Upload any file, leave Name blank

Expected behavior

I expect to be able to manipulate the as-yet-unsaved version of of this file before I save the record to the database.

Actual behavior

I get an ActiveStorage::FileNotFoundError error with the following exception cause: Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/franktisellano/Desktop/activestorage-example/storage/i6/7e/i67ej7r9nx1yz838eor5v1hwpa3o.

System configuration

Rails version: 6.0.0

Ruby version: 2.5.0

Operating System: Mac 10.13.6 High Sierra

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions