Search code examples
ruby-on-railsrails-activestorage

How to use an SMB/CIFS Internal Network Share with Active Storage?


TL;DR:
I want to use ActiveStorage to save uploaded files to a Local SMB/CIFS Network Share and access it from a second Development or Presentation Machine.

Both machines are using the same Postgres Database.


LONG VERSION:
I'm creating an internally hosted Ruby on Rails Inventory and Store application. Users need to be able to upload photos of products.

My organization wants this app to be entirely internal, so no Amazon, Google, or Azure storage options are available to me, just Disk.

How do I use ActiveStorage to store user's uploaded photos so that multiple development machines will see the same photos and not get "Broken Image" icon?

It appears that the photos work perfectly if the same server that was used to upload the photo is used to view the site. If a second developer wants to work on their own copy of the site, the image shows up as a Broken Image tag.

Any help will be greatly appreciated.

I've attempted to RSYNC the storage folder between machines. I've also attempted to Git-Commit, Git-Push and Git Pull.

Debian 9
Ruby --version
ruby 2.6.0p0
Rails 5.2.3

storage.yml:
local:
  service: Disk
  root: <%= Rails.root.join("storage") %>


ERROR message when attempting to view the Broken Image in a new Tab

Errno::ENOENT in ActiveStorage::DiskController#show
No such file or directory @ rb_file_s_mtime - <RAILS.ROOT.HERE, COMMENTED OUT>./storage/Gy/dG/GydGcRvLmbL3Loo5cYRRQspF
Extracted source (around line #63):

        return [200, {'Allow' => ALLOW_HEADER, CONTENT_LENGTH => '0'}, []]
      end
      last_modified = ::File.mtime(path).httpdate
      return [304, {}, []] if request.get_header('HTTP_IF_MODIFIED_SINCE') == last_modified

      headers = { "Last-Modified" => last_modified }

I expect a Photo to appear, on any Development or Presentation Server used to view the site. Instead, a Broken Image tag appears.


Solution

  • If the concern here is not to save nothing the cloud, maybe Minio could help for your use case.

    With minio, you can (very easy) create a private Object Storage Server (i.e. a private Amazon S3 compatible service) behind your firewall.

    Just install in your server (or Docker if you want), browse to the web GUI and create many Access Keys or Buckets as you want.

    And it have an Amazon S3 compatible API, so you can configure the S3 section of your Active Storage to talk with Minio. Very transparent.

    Minio is Open Source and easy to backup (Just copy a directory to your backup location)

    I'm am using Minio for store .zip files whith no problems.

    GitHub page: https://github.com/minio/minio

    Project Page: https://min.io/