rails icon indicating copy to clipboard operation
rails copied to clipboard

ActiveStorage direct uploads can't specify a service_name?

Open scottjg opened this issue 4 years ago • 15 comments

hey @DmitryTsepelev -- I brought my app to rails master, so that i could try out your PR: https://github.com/rails/rails/pull/34935

unfortunately, I can't seem to figure out how direct uploads can respect the service specified in the model? DirectUploadsController doesn't seem to allow passing in a service (though I'm not sure you'd want that to be user controlled necessarily?). I was expecting somehow for the rails form helpers to somehow signal to the DirectUploadsController what service to use, based on the model it was posting to.

I'm assuming I'm just missing something, but it seems like there might not be a way to use direct uploads with your PR changes? I guess you could write your own DirectUploadsController?


Steps to reproduce

use a form_with in your erb that points to a model, make a file field the same name as a has_one_attached field and direct_upload: true. then upload a file via your web browser

Expected behavior

direct upload will be directed at the service specified in the model

Actual behavior

direct upload goes to the default storage adapter

System configuration

Rails version: rails@c1ccc6a0d240

Ruby version: 2.5.1p7

scottjg avatar Apr 13 '20 20:04 scottjg

Hi @scottjg! I've reproduced the issue and investigating, thanks for catching that!

DmitryTsepelev avatar Apr 14 '20 18:04 DmitryTsepelev

as a temporary workaround for my app, i implemented my own controller/route for direct uploads:

class DirectVideoUploadsController < ActiveStorage::DirectUploadsController
  private
    def blob_args
      super.merge({
        service_name: Rails.env.production? ? :aws_video_input : :aws_video_input_dev,
      })
    end
end

scottjg avatar Apr 14 '20 22:04 scottjg

@scottjg here is a possible fix #38957, could you please take a look when you have a moment?

DmitryTsepelev avatar Apr 15 '20 11:04 DmitryTsepelev

This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open. Thank you for all your contributions.

rails-bot[bot] avatar Jul 14 '20 12:07 rails-bot[bot]

https://github.com/rails/rails/pull/38957 was never merged, so this is still an issue.

scottjg avatar Jul 14 '20 15:07 scottjg

This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open. Thank you for all your contributions.

rails-bot[bot] avatar Oct 12 '20 16:10 rails-bot[bot]

it's still an issue

DmitryTsepelev avatar Oct 12 '20 16:10 DmitryTsepelev

This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the 6-1-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open. Thank you for all your contributions.

rails-bot[bot] avatar Jan 10 '21 16:01 rails-bot[bot]

still not fixed

scottjg avatar Jan 11 '21 02:01 scottjg

Still an issue unfortunately

gstokkink avatar Mar 10 '21 15:03 gstokkink

Still an issue

egorslam avatar Jun 23 '21 14:06 egorslam

https://github.com/rails/rails/pull/38957 is the relevant PR

ghiculescu avatar Jun 23 '21 15:06 ghiculescu

Closed by #38957

skipkayhil avatar Aug 08 '22 04:08 skipkayhil

It appears the referenced PR was reverted. Was a different fix applied?

scottjg avatar Aug 08 '22 04:08 scottjg

Ack, I didn't read the thread fully, thank you

skipkayhil avatar Aug 08 '22 04:08 skipkayhil