diff --git a/README.md b/README.md index a286182..1109622 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,20 @@ class ModelDashboard < Administrate::BaseDashboard end ``` +### direct_upload +If you want to upload directly from the browser to the cloud you can use direct_upload +```ruby +class ModelDashboard < Administrate::BaseDashboard + ATTRIBUTE_TYPES = { + attachments: Field::ActiveStorage.with_options({direct_upload: true}), + # ... + } + # ... +end +``` + +Don't forget to include [ActiveStorage JavaScript](https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads). You can use `rails generate administrate:assets:javascripts` to be able to customize Administrate JavaScripts in your application. + ## Things To Do: - [x] upload single file - [x] adding image support through url_for to support 3rd party cloud storage diff --git a/app/views/fields/active_storage/_form.html.erb b/app/views/fields/active_storage/_form.html.erb index c5f9932..8bc9723 100644 --- a/app/views/fields/active_storage/_form.html.erb +++ b/app/views/fields/active_storage/_form.html.erb @@ -26,5 +26,5 @@ By default, the input is a text field for the image's URL. Add: <% end %> - <%= f.file_field field.attribute, multiple: field.many? %> + <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %> diff --git a/lib/administrate/field/active_storage.rb b/lib/administrate/field/active_storage.rb index 3ec6213..8ad9ebd 100644 --- a/lib/administrate/field/active_storage.rb +++ b/lib/administrate/field/active_storage.rb @@ -20,6 +20,10 @@ def many? data.class.name == "ActiveStorage::Attached::Many" end + def direct? + options.fetch(:direct_upload, false) + end + # def destroy_path? # options.fetch(:destroy_path, false).present? # end