fineuploader 多部分 rails
fineuploader multi-part rails
我正在尝试使用 rails 作为服务器进行分段上传以签署请求。
下面是代码片段。 signature.endpoint 是创建动作。
require 'base64'
require 'openssl'
require 'digest/sha1'
class WelcomeController < ApplicationController
skip_before_action :verify_authenticity_token
def success
render json: params
end
def index
end
def create
if(params[:headers])
signature = OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key,
params[:headers].to_s).gsub("\n", "")
params[:signature]= signature
else
conditions = params[:conditions]
conds = [
{"acl" => "private"},
{"bucket" => conditions[1][:bucket]},
{"Content-Type" => conditions[2]["Content-Type"]},
{"success_action_status" => "200"},
{"key" => conditions[4][:key]},
{"x-amz-meta-qqfilename" => conditions[5]["x-amz-meta-qqfilename"]}
]
policy = Base64.encode64({ "expiration" => params[:expiration],
"conditions" => conds
}.to_json).
gsub("\n","")
signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key, policy)
).gsub("\n","")
params[:signature]= signature
params[:policy] = policy
end
render :json => params, :status => 200 and return
end
end
这适用于大小 < 5mb 的文件,即 if-else 块的 else 部分。
但是,当文件大小 > 5mb 时,请求未正确签名。
请提出我在这里遗漏了什么。
索恩:
require 'base64'
require 'openssl'
require 'digest/sha1'
class WelcomeController < ApplicationController
skip_before_action :verify_authenticity_token
def success
render json: params
end
def index
end
def create
if(params[:headers])
logger.info params[:welcome][:headers]
signature = Base64.encode64(OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key,
params[:welcome][:headers])).gsub("\n", "")
params[:signature]= signature
else
conditions = params[:conditions]
conds = [
{"acl" => "public-read"},
{"bucket" => conditions[1][:bucket]},
{"Content-Type" => conditions[2]["Content-Type"]},
{"success_action_status" => "200"},
{"key" => conditions[4][:key]},
{"x-amz-meta-qqfilename" => conditions[5]["x-amz-meta-qqfilename"]}
]
policy = Base64.encode64({ "expiration" => params[:expiration],
"conditions" => conds
}.to_json).
gsub("\n","")
signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key, policy)
).gsub("\n","")
params[:signature]= signature
params[:policy] = policy
end
logger.info signature
render :json => params, :status => 200 and return
end
end
我正在尝试使用 rails 作为服务器进行分段上传以签署请求。 下面是代码片段。 signature.endpoint 是创建动作。
require 'base64'
require 'openssl'
require 'digest/sha1'
class WelcomeController < ApplicationController
skip_before_action :verify_authenticity_token
def success
render json: params
end
def index
end
def create
if(params[:headers])
signature = OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key,
params[:headers].to_s).gsub("\n", "")
params[:signature]= signature
else
conditions = params[:conditions]
conds = [
{"acl" => "private"},
{"bucket" => conditions[1][:bucket]},
{"Content-Type" => conditions[2]["Content-Type"]},
{"success_action_status" => "200"},
{"key" => conditions[4][:key]},
{"x-amz-meta-qqfilename" => conditions[5]["x-amz-meta-qqfilename"]}
]
policy = Base64.encode64({ "expiration" => params[:expiration],
"conditions" => conds
}.to_json).
gsub("\n","")
signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key, policy)
).gsub("\n","")
params[:signature]= signature
params[:policy] = policy
end
render :json => params, :status => 200 and return
end
end
这适用于大小 < 5mb 的文件,即 if-else 块的 else 部分。 但是,当文件大小 > 5mb 时,请求未正确签名。
请提出我在这里遗漏了什么。
索恩:
require 'base64'
require 'openssl'
require 'digest/sha1'
class WelcomeController < ApplicationController
skip_before_action :verify_authenticity_token
def success
render json: params
end
def index
end
def create
if(params[:headers])
logger.info params[:welcome][:headers]
signature = Base64.encode64(OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key,
params[:welcome][:headers])).gsub("\n", "")
params[:signature]= signature
else
conditions = params[:conditions]
conds = [
{"acl" => "public-read"},
{"bucket" => conditions[1][:bucket]},
{"Content-Type" => conditions[2]["Content-Type"]},
{"success_action_status" => "200"},
{"key" => conditions[4][:key]},
{"x-amz-meta-qqfilename" => conditions[5]["x-amz-meta-qqfilename"]}
]
policy = Base64.encode64({ "expiration" => params[:expiration],
"conditions" => conds
}.to_json).
gsub("\n","")
signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
key, policy)
).gsub("\n","")
params[:signature]= signature
params[:policy] = policy
end
logger.info signature
render :json => params, :status => 200 and return
end
end