TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.94k stars 173 forks source link

Direct upload or chunked file upload support? #448

Open 0000sir opened 1 year ago

0000sir commented 1 year ago

Thank you for the great admin framework, but I have a tiny problem recently: Direct upload for active storage is not working, the option direct_upload:true didn't affect the html output, I followed codes in lib/trestle/form/fields/file_field.rb, and have no idea for this.

I'm working with S3 protocol for active storage and direct upload works fine if I use it with scaffold controllers, Here's my code:

file_field :file, direct_upload: true, multiple: true, class: 'hello-director', custom: false, accept: 'text/html'

HTML generated:

<div class="form-group"><label class="control-label" for="video_file">Video</label><input multiple="multiple" class="hello-director" custom="false" accept="text/html" type="file" name="video[file][]" id="video_file"></div>

Everything works except the _directupload option, What I'm missing?

Please help me with this, or I have to rewrite the hole admin panel myself.

Or, is there any other way to upload files in chunks?

Thank you very much.

BTW: trestle-active_storage Gem not help, seems like the _directupload was simply ignored

spohlenz commented 1 year ago

The current releases of Rails (including 7.0.x) don't seem to play well with ActiveStorage when used from an engine. It looks like this may be fixed in 7.1 but in the mean time, you can add the following to your config/initializers/trestle.rb:

config.helper do
  delegate :rails_direct_uploads_url, to: :main_app
end

When rendering ActiveStorage files within the admin, you may also need to precede some route calls with main_app..

0000sir commented 1 year ago

@spohlenz Thank you, direct upload works great (with trestle-active_storage Gem)! It's would be nice if this is documented.