Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何获取临时授权 STS #68

Closed
quoyi opened this issue Oct 6, 2020 · 2 comments
Closed

如何获取临时授权 STS #68

quoyi opened this issue Oct 6, 2020 · 2 comments

Comments

@quoyi
Copy link

quoyi commented Oct 6, 2020

需要客户端通过 js 直传 OSS,内嵌 iframe 无法直接通过 /rails/active_storage/direct_uploads 上传,需要获取 STS 后再上传 OSS。

# routes.rb
namespace :api do
  get :sts, to: 'oss#sts'
end

# controller.rb
def sts
  # new file parameters
  # params[:filename] => 'test.txt'   &&  params[:byte_size] =>  710221

  # old file information
  # ActiveStorage::Blob.find_by_filename(params[:filename])  => #<ActiveStorage::Blob id: 33, key: "phecdsvaqca2q0h4tacscis7r7wl", filename: "test.txt",  ... byte_size: 689744 ...>

  # Get direct upload signed url by `url_for_direct_upload` ?
end
@huacnlee
Copy link
Owner

huacnlee commented Oct 8, 2020

https://guides.rubyonrails.org/active_storage_overview.html#direct-uploads

ActiveStorage 的 DirectUpload 功能无法满足?

@quoyi
Copy link
Author

quoyi commented Oct 8, 2020

https://guides.rubyonrails.org/active_storage_overview.html#direct-uploads

ActiveStorage 的 DirectUpload 功能无法满足?

是的,没办法直接使用。不过我已经通过 “override” direct_uploads action 绕过了 csrf、 session、headers 问题,手动创建 blob 对象直传后关联 signed_id ,具体步骤请移步 Issues 32208 感谢回复。

只需要两个action /api/direct_uploads/api/assign

@quoyi quoyi closed this as completed Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants