Skip to content

Commit

Permalink
Adds option to support direct uploads (#14)
Browse files Browse the repository at this point in the history
* Adds option to support direct uploads

* Adds documentation for direct_upload option
  • Loading branch information
kdiogenes authored and Dreamersoul committed Feb 11, 2019
1 parent 9124d55 commit 2d6e23f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/fields/active_storage/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
</div>
4 changes: 4 additions & 0 deletions lib/administrate/field/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d6e23f

Please sign in to comment.