title: Rails ActiveStorage issue: "file not found" error for rails_blob_path, even though the path works manually
body: <p>I have a small Rails app that works fine locally, uploading a docx file using ActiveStorage and converting it to html (among other things). To deploy this to Heroku, I need to change from using the local filesystem for storage to using S3 and thus to change how I generate the path to the file. </p>
  
  <p>My research suggests that <code>rails_blob_path</code> (or <code>_url</code>) should be what I need but I'm getting a "file not found" error, even though the file path works when I then try it manually.</p>
  
  <p>How can I generate a path for an attached file that I can use for further conversion? The docs say it's straightforward but I can't get it to work!</p>
  
  <hr>
  
  <p>My app has Projects, each of which must have a File attached, via ActiveStorage. After the Project is created (with its attached file), the file is processed and its content displayed to the user (extracting the text from the Word file, matching that against word lists and storing both the resulting HTML and the word lists for further manual editing by the user).</p>
  
  <p>My original approach was to have this method in the Project model:</p>
  
  <pre><code>def real_file_path
    ActiveStorage::Blob.service.send(:path_for, file.key)
  end
  </code></pre>
  
  <p>And then, in the controller, I called this method to do the actual conversion:</p>
  
  <pre><code>def convert_docx_file
    _file_contents = ''
    _doc = Docx::Document.open(@project.real_file_path)
    _doc.paragraphs.each do |p|
      _file_contents += p.to_html
    end
    @project.update_attributes(file_contents: _file_contents)
  end
  </code></pre>
  
  <p>(This uses the DOCX gem to create a suitable object and then iterate over it and convert the paragraphs to HTML.)</p>
  
  <p>The problematic step now is the creation of the _doc object. The above code works fine on the local filesystem. For S3 usage, after a fair amount of research and experimentation, I've changed it to:</p>
  
  <pre><code>.
  .
    _doc = Docx::Document.open(rails_blob_path(@project.file))
  .
  .
  .
  </code></pre>
  
  <p>When run on my local machine, this produces the error: <code>Zip::Error in ProjectsController#show
  File /rails/active_storage/blobs/BLAH_BLAH_BLAH/original%20file.docx not found</code>. But, when I then copy and paste the address into the browser, it downloads fine.</p>
  
  <p>Can anyone let me know how to get the correct file path so that I can get the conversion working again?</p>