Shrine

How to test Direct Upload in Dev Env using Shrine::Storage::FileSystem?

Hi all,

I’m currently trying to build direct upload using uppy from frontend using the :presign_endpoint plugin. I’m using Shrine::Storage::FileSystem for local development environment Shrine::Storage::GoogleCloudStorage environment. I would like to be able to test direct upload using FileSystem instead of having to pay for a test instance of cloud storage. Then for production, I can just choose the correct Shrine storage and it will work as expected.

I came across this commit https://github.com/shrinerb/shrine/commit/a653e1a94118f9e47d95cd3d20b1f8ab910201f4 (can’t put link in post for new user) from 2016 in v1.4.0 that supports dummy presign for storage systems that does not support it like Shrine::Storage::FileSystem. Looking at the code now for v3.4.1, I’m guessing this feature is no longer supported and the structure of the code base has changed tremendously.

How do you test direct upload when in development? Do you provision a test GCS or S3 for testing direct upload in local development env?

Appreciate any ideas of testing direct upload in local development environment.

Found a way to provide Presign endpoint for Filesystem. Following this code, we are able to provide our own presign generator.

https://github.com/shrinerb/shrine/blob/0bb1a12703403cfe06261c11f4858b3c7f6130dc/lib/shrine/plugins/presign_endpoint.rb#L147-L148

# config/initializer/shrine.rb

if Rails.env.production? 
  # Using Shrine::Storage::GoogleCloudStorage in Production env so presign endpoint
  #   is already working.
  Shrine.plugin :presign_endpoint 
else 
  # Using Shrine::Storage::FileSystem in Dev and Test env so I have to generate my own
  #   presign endpoint. This can be a fix endpoint only available in Dev and Test environment
  #   to replicate the direct upload experience. 
  Shrine.plugin :presign_endpoint, presign: -> (location, options, request) do
    # provide an endpoint for frontend to use for direct upload. 
    { endpoint: "http://localhost:3000/photos/direct_upload" }
  end
end