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

direct_upload在rails 6.1下有问题 #70

Closed
clwy-cn opened this issue Jan 26, 2021 · 2 comments
Closed

direct_upload在rails 6.1下有问题 #70

clwy-cn opened this issue Jan 26, 2021 · 2 comments

Comments

@clwy-cn
Copy link
Contributor

clwy-cn commented Jan 26, 2021

操作一

Rails 6.1中,对active storage,在模型中增加了service新的配置方法,例如:

# models/user.rb

has_one_attached :avatar, service: :aliyun

development.rb中,未做修改,保持了默认

# config/environments/development.rb

config.active_storage.service = :local

非direct_upload文件时,可以正常上传到阿里云oss

<%= form.file_field :avatar %>

使用direct_upload传文件时,依然上传到本地,而不是阿里云oss上。也就说模型中配置的service,根本没有生效。

<%= form.file_field :avatar, direct_upload: true %>

chrome的netwok中,看不到请求阿里云oss的记录。

操作二

模型中,不配置service

# models/user.rb

has_one_attached :avatar

development.rb中,修改为:aliyun

# config/environments/development.rb

config.active_storage.service = :aliyun

再次测试direct_upload文件,可以正确上传到阿里云oss了。
chrome的netwok中,也可以看到请求阿里云oss的记录。

结论:

初步判断,

  • 在model中配置的service: :aliyun,在direct_upload方式下,完全没有生效。
  • 非direct_upload方式下,可以正确的上传到阿里云oss

我不确定是Rails的问题,还是activestorage-aliyun的问题?

@huacnlee
Copy link
Owner

huacnlee commented Jan 26, 2021

#71

我在测试里面试了一下,没重现出来

@clwy-cn
Copy link
Contributor Author

clwy-cn commented Jan 26, 2021

我尝试运行了你的代码

cd test/dummy
rails s

选择并上传avatar和files后

提示错误:

image

检查阿里云oss

发现avatar上传成功,files的上传全部失败。

image

检查了项目本身

发现tmp/storage目录下,出现了direct_upload上传的files文件。说明has_many_attached :files, service: :aliyun未生效,依然传到:local中了

image

我还找到了Rails上关于这个问题的issue和pr

目前看来,问题出在Rails本身上了

rails/rails#34935 (comment)

rails/rails#38957

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