trestle icon indicating copy to clipboard operation
trestle copied to clipboard

Direct upload or chunked file upload support?

Open 0000sir opened this issue 1 year ago • 2 comments

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 direct_upload 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 direct_upload was simply ignored

0000sir avatar May 27 '23 14:05 0000sir

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..

spohlenz avatar May 28 '23 03:05 spohlenz

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

0000sir avatar May 29 '23 08:05 0000sir