Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
be526d16
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,发现更多精彩内容 >>
提交
be526d16
编写于
7月 17, 2017
作者:
M
Michael Herold
提交者:
George Claghorn
7月 17, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add direct upload support to GCS service
上级
94a450ac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
2 deletion
+63
-2
lib/active_storage/service/gcs_service.rb
lib/active_storage/service/gcs_service.rb
+11
-0
test/direct_uploads_controller_test.rb
test/direct_uploads_controller_test.rb
+32
-2
test/service/gcs_service_test.rb
test/service/gcs_service_test.rb
+20
-0
未找到文件。
lib/active_storage/service/gcs_service.rb
浏览文件 @
be526d16
...
...
@@ -53,6 +53,17 @@ def url(key, expires_in:, disposition:, filename:)
end
end
def
url_for_direct_upload
(
key
,
expires_in
:,
content_type
:,
content_length
:)
instrument
:url
,
key
do
|
payload
|
generated_url
=
bucket
.
signed_url
key
,
method:
"PUT"
,
expires:
expires_in
,
content_type:
content_type
payload
[
:url
]
=
generated_url
generated_url
end
end
private
def
file_for
(
key
)
bucket
.
file
(
key
)
...
...
test/direct_uploads_controller_test.rb
浏览文件 @
be526d16
...
...
@@ -7,7 +7,7 @@
require
"active_storage/direct_uploads_controller"
if
SERVICE_CONFIGURATIONS
[
:s3
]
class
ActiveStorage::DirectUploadsControllerTest
<
ActionController
::
TestCase
class
ActiveStorage::
S3
DirectUploadsControllerTest
<
ActionController
::
TestCase
setup
do
@blob
=
create_blob
@routes
=
Routes
...
...
@@ -32,5 +32,35 @@ class ActiveStorage::DirectUploadsControllerTest < ActionController::TestCase
end
end
else
puts
"Skipping Direct Upload tests because no S3 configuration was supplied"
puts
"Skipping S3 Direct Upload tests because no S3 configuration was supplied"
end
if
SERVICE_CONFIGURATIONS
[
:gcs
]
class
ActiveStorage::GCSDirectUploadsControllerTest
<
ActionController
::
TestCase
setup
do
@blob
=
create_blob
@routes
=
Routes
@controller
=
ActiveStorage
::
DirectUploadsController
.
new
@config
=
SERVICE_CONFIGURATIONS
[
:gcs
]
@old_service
=
ActiveStorage
::
Blob
.
service
ActiveStorage
::
Blob
.
service
=
ActiveStorage
::
Service
.
configure
(
:gcs
,
SERVICE_CONFIGURATIONS
)
end
teardown
do
ActiveStorage
::
Blob
.
service
=
@old_service
end
test
"creating new direct upload"
do
post
:create
,
params:
{
blob:
{
filename:
"hello.txt"
,
byte_size:
6
,
checksum:
Digest
::
MD5
.
base64digest
(
"Hello"
),
content_type:
"text/plain"
}
}
details
=
JSON
.
parse
(
@response
.
body
)
assert_match
%r{storage
\.
googleapis
\.
com/
#{
@config
[
:bucket
]
}
}
,
details
[
"url"
]
assert_equal
"hello.txt"
,
GlobalID
::
Locator
.
locate_signed
(
details
[
"sgid"
]).
filename
.
to_s
end
end
else
puts
"Skipping GCS Direct Upload tests because no GCS configuration was supplied"
end
test/service/gcs_service_test.rb
浏览文件 @
be526d16
require
"service/shared_service_tests"
require
"httparty"
if
SERVICE_CONFIGURATIONS
[
:gcs
]
class
ActiveStorage::Service::GCSServiceTest
<
ActiveSupport
::
TestCase
...
...
@@ -6,6 +7,25 @@ class ActiveStorage::Service::GCSServiceTest < ActiveSupport::TestCase
include
ActiveStorage
::
Service
::
SharedServiceTests
test
"direct upload"
do
begin
key
=
SecureRandom
.
base58
(
24
)
data
=
"Something else entirely!"
direct_upload_url
=
@service
.
url_for_direct_upload
(
key
,
expires_in:
5
.
minutes
,
content_type:
"text/plain"
,
content_length:
data
.
size
)
HTTParty
.
put
(
direct_upload_url
,
body:
data
,
headers:
{
"Content-Type"
=>
"text/plain"
},
debug_output:
STDOUT
)
assert_equal
data
,
@service
.
download
(
key
)
ensure
@service
.
delete
key
end
end
test
"signed URL generation"
do
travel_to
Time
.
now
do
url
=
SERVICE
.
bucket
.
signed_url
(
FIXTURE_KEY
,
expires:
120
)
+
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录