Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ccaba581
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,发现更多精彩内容 >>
提交
ccaba581
编写于
7月 04, 2017
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Differentiate between io streams and read data
上级
8da081c3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
16 addition
and
16 deletion
+16
-16
lib/active_file/blob.rb
lib/active_file/blob.rb
+6
-6
lib/active_file/site.rb
lib/active_file/site.rb
+1
-1
lib/active_file/sites/disk_site.rb
lib/active_file/sites/disk_site.rb
+2
-2
lib/active_file/sites/gcs_site.rb
lib/active_file/sites/gcs_site.rb
+2
-2
lib/active_file/sites/mirror_site.rb
lib/active_file/sites/mirror_site.rb
+2
-2
lib/active_file/sites/s3_site.rb
lib/active_file/sites/s3_site.rb
+2
-2
test/blob_test.rb
test/blob_test.rb
+1
-1
未找到文件。
lib/active_file/blob.rb
浏览文件 @
ccaba581
...
...
@@ -11,16 +11,16 @@ class ActiveFile::Blob < ActiveRecord::Base
class_attribute
:site
class
<<
self
def
build_after_upload
(
data
:,
filename
:,
content_type:
nil
,
metadata:
nil
)
def
build_after_upload
(
io
:,
filename
:,
content_type:
nil
,
metadata:
nil
)
new
.
tap
do
|
blob
|
blob
.
filename
=
name
blob
.
content_type
=
content_type
# Marcel::MimeType.for(data, name: name, declared_type: content_type)
blob
.
upload
data
blob
.
upload
io
end
end
def
create_after_upload!
(
data
:,
filename
:,
content_type:
nil
,
metadata:
nil
)
build_after_upload
(
data:
data
,
filename:
filename
,
content_type:
content_type
,
metadata:
metadata
).
tap
(
&
:save!
)
def
create_after_upload!
(
io
:,
filename
:,
content_type:
nil
,
metadata:
nil
)
build_after_upload
(
io:
io
,
filename:
filename
,
content_type:
content_type
,
metadata:
metadata
).
tap
(
&
:save!
)
end
end
...
...
@@ -38,8 +38,8 @@ def url(disposition: :inline, expires_in: 5.minutes)
end
def
upload
(
data
)
site
.
upload
(
key
,
data
)
def
upload
(
io
)
site
.
upload
(
key
,
io
)
self
.
checksum
=
site
.
checksum
(
key
)
self
.
byte_size
=
site
.
byte_size
(
key
)
...
...
lib/active_file/site.rb
浏览文件 @
ccaba581
...
...
@@ -3,7 +3,7 @@ class ActiveFile::Site
def
initialize
end
def
upload
(
key
,
data
)
def
upload
(
key
,
io
)
raise
NotImplementedError
end
...
...
lib/active_file/sites/disk_site.rb
浏览文件 @
ccaba581
...
...
@@ -9,9 +9,9 @@ def initialize(root:)
end
def
upload
(
key
,
data
)
def
upload
(
key
,
io
)
File
.
open
(
make_path_for
(
key
),
"wb"
)
do
|
file
|
while
chunk
=
data
.
read
(
65536
)
while
chunk
=
io
.
read
(
65536
)
file
.
write
(
chunk
)
end
end
...
...
lib/active_file/sites/gcs_site.rb
浏览文件 @
ccaba581
...
...
@@ -8,8 +8,8 @@ def initialize(project:, keyfile:, bucket:)
@bucket
=
@client
.
bucket
(
bucket
)
end
def
upload
(
key
,
data
)
bucket
.
create_file
(
data
,
key
)
def
upload
(
key
,
io
)
bucket
.
create_file
(
io
,
key
)
end
def
download
(
key
)
...
...
lib/active_file/sites/mirror_site.rb
浏览文件 @
ccaba581
...
...
@@ -5,8 +5,8 @@ def initialize(sites:)
@sites
=
sites
end
def
upload
(
key
,
data
)
perform_across_sites
:upload
,
key
,
data
def
upload
(
key
,
io
)
perform_across_sites
:upload
,
key
,
io
end
def
download
(
key
)
...
...
lib/active_file/sites/s3_site.rb
浏览文件 @
ccaba581
...
...
@@ -8,8 +8,8 @@ def initialize(access_key_id:, secret_access_key:, region:, bucket:)
@bucket
=
@client
.
bucket
(
bucket
)
end
def
upload
(
key
,
data
)
object_for
(
key
).
put
(
body:
data
)
def
upload
(
key
,
io
)
object_for
(
key
).
put
(
body:
io
)
end
def
download
(
key
)
...
...
test/blob_test.rb
浏览文件 @
ccaba581
...
...
@@ -22,6 +22,6 @@ class ActiveFile::BlobTest < ActiveSupport::TestCase
private
def
create_blob
(
data:
"Hello world!"
,
filename:
"hello.txt"
,
content_type:
"text/plain"
)
ActiveFile
::
Blob
.
create_after_upload!
data
:
StringIO
.
new
(
data
),
filename:
filename
,
content_type:
content_type
ActiveFile
::
Blob
.
create_after_upload!
io
:
StringIO
.
new
(
data
),
filename:
filename
,
content_type:
content_type
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录