-
Notifications
You must be signed in to change notification settings - Fork 60
Conversation
# Conflicts: # lib/active_storage/engine.rb # lib/active_storage/service.rb # lib/active_storage/service/disk_service.rb # lib/active_storage/service/s3_service.rb # test/service/s3_service_test.rb # test/test_helper.rb
Going to merge this partial PR as-is. The direct url creation works for S3 when tested in the browser. Still haven't found out why the test doesn't pass, but will continue to work on that. We can work on the JS element in a separate PR. (I got tired of keeping this branch up to date with rapid changes to master). |
|
||
config.after_initialize do |app| | ||
app.routes.prepend do | ||
get "/rails/blobs/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_blob | ||
eval(File.read(File.expand_path("../routes.rb", __FILE__))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an engine so if we create a file config/routes.rb
inside the gem it will be loaded without us having to add new initializer. Same with controllers. If the controllers are inside app/controllers
they will be automatically required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, of course. Will switch over to that 👍
@dhh How do you feel about implementing this feature without depending on the On one hand, it's true that Amazon built that gem, so it will probably always be on sync with the HTTP calls needed to store/retrieve/delete files on S3. On the other hand, I asked this question myself when I created a gem called star (https://github.com/claudiob/star) that lets users store files on S3 and retrieve them with expiring URLs. I started with Let me know if this is something that you wanna look out, or else if you are happy with sticking with |
oh good point @claudiob. aws-sdk includes some monkey patches to Net::Http and I'd feel more comfortable not shipping that gem by default to all Rails applications. |
aws-sdk isn't a dep in the gemspec. Think it makes sense for us to track the official clients for the Big Three cloud storage providers. Implementing a service that uses a different client is pretty straightforward, and could even be bundled with the client 😊 |
We can support direct uploads by exposing an endpoint that'll create the destination URL for the service and return a signed blob gid that can be submitted with the form on completed upload.
This pull request currently just exposes the
url_for_direct_upload
for the S3 service, but we should provide it for all services, including disk, so we can fully test it.I'm having some trouble testing the generated URL. I can make it work with JavaScript in a browser, but stuck on something when submitting the upload request via HTTParty. Getting a signing error.
Secondly, I'd like to include the JavaScript needed to make this fully work as well. I'm thinking that we do something like
form.file_field :avatar, 'data-direct-upload': rails_direct_uploads_path
(which again should be wrapped inform.direct_upload_file_field :avatar
, which is then picked up by a Rails UJS-like helped that on file picking does something like:If anyone would like to assist bringing this PR to completion, please do join the fun.