I have a problem but i’m not trully sure if it’s a bug or i’m using shrine in the wrong way.
I was trying to use the download_endpoint with authorization. This is my uploader
class FileUploader < Shrine plugin :instrumentation plugin :add_metadata plugin :download_endpoint, redirect: true, prefix: "file" plugin :pretty_location end
Then i added the route on routes.rb
Rails.application.routes.draw do ... resources :catalogs do member do get "/file/*rest", to: "catalogs#file", as: file' end end end
And the controller
class CatalogController < ApplicationController ... def file set_rack_response FileUploader.download_response(request.env) end end
The thing is when trying to generate an url for this nested route
/catalog/123/file/eyJpZCI6ImNhbmRpZGF0ZS...(rest of hashed metadata)
It’s not working, as i’m getting an exception undefined method `post_match’ for nil:NilClass
I trace the error up to the DownloadEndpoint plugin. s i see the problem is that on the download_response method there is a “trick” to find the hashed metadata, but that trick checks that the path info strictly start with the prefix of the uploader. So if i have scoped/namespaces routes or nested route like in this case, it doesn’t work.
I know shrine is not rails based, but not sure how should i resolve this one, or if it’s something that should be fixed on shrine.
There is an additional situation i see, that i can’t keep the original filename if using the redirect: true option (pointing to the direct url instead of streaming the file), but i think that is expected and there is no way to use the original filename. Or a file can be uploaded having the original filename instead of the autogenerated id?
Thanks in advance