0
我想要獲得多部分上載與軌道作爲服務器簽署請求。 以下是代碼片段。 signature.endpoint是創建操作。fineuploader多部分導軌
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塊的一部分。 但是,請求在文件大小> 5mb時未正確簽名。
請建議我在這裏錯過什麼。
你只是佔一個政策文件。當文件大於5 MB時,它將被拆分爲塊,並使用S3分段上傳REST API。在這種情況下,一串標頭必須改爲簽名。有關更多詳細信息,請參見[分塊S3上載文檔中的章節](http://docs.fineuploader.com/branch/master/endpoint_handlers/amazon-s3.html#chunked-uploads)。 –
我的壞處。如果size> 5mb,我錯過了base64編碼的結果。 現在就試試。並在此更新。 – user2307034
當你得到你的代碼的工作,一定要作爲答案發布,然後接受你的答案。 –