Last active
December 29, 2015 15:19
-
-
Save jay16/7689655 to your computer and use it in GitHub Desktop.
七牛存储-上传文件-ruby-sdk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'qiniu-rs' | |
AK = "access_key" | |
SK = "secret_key " | |
bucket_name = "七牛空间名称" | |
backup_file = "待上传文件(绝对路径)" | |
Qiniu::RS.establish_connection!({ | |
:access_key => AK, | |
:secret_key => SK | |
}) | |
token = Qiniu::RS.generate_upload_token({ | |
:scope => bucket_name, | |
:expires_in => 3600 | |
# :callback_url => callback_url, | |
# :callback_body => callback_body, | |
# :callback_body_type => callback_body_type, | |
# :customer => end_user_id, | |
# :escape => allow_upload_callback_api, | |
# :async_options => async_callback_api_commands, | |
# :return_body => custom_response_body | |
}) | |
puts token | |
ret = Qiniu::RS.upload_file({ | |
:uptoken => token, | |
:file => backup_file, | |
:bucket => bucket_name, | |
:key => File.basename(backup_file) # 上传至七牛空间后显示的文件名称 | |
}) | |
puts ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment