Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
edcd32ed
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
edcd32ed
编写于
1月 08, 2018
作者:
G
George Claghorn
提交者:
GitHub
1月 08, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #31650 from rosa/master
Allow overriding filename in `Blob#service_url`
上级
7c693512
8f52d935
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
4 deletion
+15
-4
activestorage/app/models/active_storage/blob.rb
activestorage/app/models/active_storage/blob.rb
+1
-1
activestorage/test/models/blob_test.rb
activestorage/test/models/blob_test.rb
+14
-3
未找到文件。
activestorage/app/models/active_storage/blob.rb
浏览文件 @
edcd32ed
...
...
@@ -201,7 +201,7 @@ def representable?
# with users. Instead, the +service_url+ should only be exposed as a redirect from a stable, possibly authenticated URL.
# Hiding the +service_url+ behind a redirect also gives you the power to change services without updating all URLs. And
# it allows permanent URLs that redirect to the +service_url+ to be cached in the view.
def
service_url
(
expires_in:
service
.
url_expires_in
,
disposition: :inline
)
def
service_url
(
expires_in:
service
.
url_expires_in
,
disposition: :inline
,
filename:
self
.
filename
)
service
.
url
key
,
expires_in:
expires_in
,
disposition:
forcibly_serve_as_binary?
?
:attachment
:
disposition
,
filename:
filename
,
content_type:
content_type
end
...
...
activestorage/test/models/blob_test.rb
浏览文件 @
edcd32ed
...
...
@@ -50,6 +50,16 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
end
end
test
"urls allow for custom filename"
do
blob
=
create_blob
(
filename:
"original.txt"
)
new_filename
=
ActiveStorage
::
Filename
.
new
(
"new.txt"
)
freeze_time
do
assert_equal
expected_url_for
(
blob
),
blob
.
service_url
assert_equal
expected_url_for
(
blob
,
filename:
new_filename
),
blob
.
service_url
(
filename:
new_filename
)
end
end
test
"purge deletes file from external service"
do
blob
=
create_blob
...
...
@@ -66,8 +76,9 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
end
private
def
expected_url_for
(
blob
,
disposition: :inline
)
query_string
=
{
content_type:
blob
.
content_type
,
disposition:
"
#{
disposition
}
;
#{
blob
.
filename
.
parameters
}
"
}.
to_param
"/rails/active_storage/disk/
#{
ActiveStorage
.
verifier
.
generate
(
blob
.
key
,
expires_in:
5
.
minutes
,
purpose: :blob_key
)
}
/
#{
blob
.
filename
}
?
#{
query_string
}
"
def
expected_url_for
(
blob
,
disposition: :inline
,
filename:
nil
)
filename
||=
blob
.
filename
query_string
=
{
content_type:
blob
.
content_type
,
disposition:
"
#{
disposition
}
;
#{
filename
.
parameters
}
"
}.
to_param
"/rails/active_storage/disk/
#{
ActiveStorage
.
verifier
.
generate
(
blob
.
key
,
expires_in:
5
.
minutes
,
purpose: :blob_key
)
}
/
#{
filename
}
?
#{
query_string
}
"
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录