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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
lib/paperclip/storage/qiniu.rb
+25
-4
spec/lib/paperclip/storage/qiniu_spec.rb
+2
-2
No files found.
lib/paperclip/storage/qiniu.rb
View file @
e1bd195a
...
...
@@ -46,16 +46,23 @@ module Paperclip
def
flush_deletes
init
for
path
in
@queued_for_delete
do
::
Qiniu
::
RS
.
delete
(
bucket
,
path
)
::
Qiniu
::
RS
.
delete
(
bucket
,
fix_path
(
path
)
)
end
@queued_for_delete
=
[]
end
def
public_url
(
style
=
default_style
)
init
res
=
::
Qiniu
::
RS
.
get
(
bucket
,
path
(
style
))
return
res
[
"url"
]
if
res
nil
if
@options
[
:qiniu_host
]
"
#{
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
end
end
end
private
...
...
@@ -67,6 +74,7 @@ module Paperclip
end
def
upload
(
file
,
path
)
path
=
fix_path
(
path
)
remote_upload_url
=
::
Qiniu
::
RS
.
put_auth
opts
=
{
:url
=>
remote_upload_url
,
:file
=>
file
.
path
,
...
...
@@ -75,12 +83,25 @@ module Paperclip
:mime_type
=>
file
.
content_type
,
:enable_crc32_check
=>
true
}
::
Qiniu
::
RS
.
upload
opts
log
"bucket=
#{
bucket
}
, key=
#{
path
}
, mime_type=
#{
file
.
content_type
}
"
log
::
Qiniu
::
RS
.
get
(
bucket
,
path
)
end
def
bucket
@options
[
:bucket
]
||
raise
(
"bucket is nil"
)
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
spec/lib/paperclip/storage/qiniu_spec.rb
View file @
e1bd195a
...
...
@@ -3,8 +3,8 @@ require 'paperclip/storage/qiniu'
module
Paperclip::Storage
describe
Qiniu
do
it
"should works"
do
1
.
should
==
1
context
'exists?'
do
pending
"it's hard to test paperclip plugin"
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