Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip-qiniu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip-qiniu
Commits
e1bd195a
Commit
e1bd195a
authored
Jul 17, 2012
by
LI Daobing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
it works for public host
but still have problem in generate path
parent
ce137c46
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
lib/paperclip/storage/qiniu.rb
+24
-3
spec/lib/paperclip/storage/qiniu_spec.rb
+2
-2
No files found.
lib/paperclip/storage/qiniu.rb
View file @
e1bd195a
...
@@ -46,17 +46,24 @@ module Paperclip
...
@@ -46,17 +46,24 @@ module Paperclip
def
flush_deletes
def
flush_deletes
init
init
for
path
in
@queued_for_delete
do
for
path
in
@queued_for_delete
do
::
Qiniu
::
RS
.
delete
(
bucket
,
path
)
::
Qiniu
::
RS
.
delete
(
bucket
,
fix_path
(
path
)
)
end
end
@queued_for_delete
=
[]
@queued_for_delete
=
[]
end
end
def
public_url
(
style
=
default_style
)
def
public_url
(
style
=
default_style
)
init
init
res
=
::
Qiniu
::
RS
.
get
(
bucket
,
path
(
style
))
if
@options
[
:qiniu_host
]
return
res
[
"url"
]
if
res
"
#{
dynamic_fog_host_for_style
(
style
)
}
/
#{
fix_path
(
path
(
style
))
}
"
else
res
=
::
Qiniu
::
RS
.
get
(
bucket
,
fix_path
(
path
(
style
)))
if
res
res
[
"url"
]
else
nil
nil
end
end
end
end
private
private
...
@@ -67,6 +74,7 @@ module Paperclip
...
@@ -67,6 +74,7 @@ module Paperclip
end
end
def
upload
(
file
,
path
)
def
upload
(
file
,
path
)
path
=
fix_path
(
path
)
remote_upload_url
=
::
Qiniu
::
RS
.
put_auth
remote_upload_url
=
::
Qiniu
::
RS
.
put_auth
opts
=
{
:url
=>
remote_upload_url
,
opts
=
{
:url
=>
remote_upload_url
,
:file
=>
file
.
path
,
:file
=>
file
.
path
,
...
@@ -75,12 +83,25 @@ module Paperclip
...
@@ -75,12 +83,25 @@ module Paperclip
:mime_type
=>
file
.
content_type
,
:mime_type
=>
file
.
content_type
,
:enable_crc32_check
=>
true
}
:enable_crc32_check
=>
true
}
::
Qiniu
::
RS
.
upload
opts
::
Qiniu
::
RS
.
upload
opts
log
"bucket=
#{
bucket
}
, key=
#{
path
}
, mime_type=
#{
file
.
content_type
}
"
log
::
Qiniu
::
RS
.
get
(
bucket
,
path
)
log
::
Qiniu
::
RS
.
get
(
bucket
,
path
)
end
end
def
bucket
def
bucket
@options
[
:bucket
]
||
raise
(
"bucket is nil"
)
@options
[
:bucket
]
||
raise
(
"bucket is nil"
)
end
end
def
dynamic_fog_host_for_style
(
style
)
if
@options
[
:qiniu_host
].
respond_to?
(
:call
)
@options
[
:qiniu_host
].
call
(
self
)
else
@options
[
:qiniu_host
]
end
end
def
fix_path
(
path
)
path
.
gsub
(
/^\//
,
''
)
end
end
end
end
end
end
end
spec/lib/paperclip/storage/qiniu_spec.rb
View file @
e1bd195a
...
@@ -3,8 +3,8 @@ require 'paperclip/storage/qiniu'
...
@@ -3,8 +3,8 @@ require 'paperclip/storage/qiniu'
module
Paperclip::Storage
module
Paperclip::Storage
describe
Qiniu
do
describe
Qiniu
do
it
"should works"
do
context
'exists?'
do
1
.
should
==
1
pending
"it's hard to test paperclip plugin"
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment