I am trying to create client side uploads using POST with AWS signature version 4. According to documents
When I create a signature on the server side, and me to get an accurate get matching
However, when I use the page with AWS sign This error is:
Signature dots notmatch We have calculated the signature of the request, it does not match the signature you provided.
OpenSSL :: HMAC.hexdigest ( 'SHA256', signing_key (string_to_sign: your keys and signature method
This is the code I used check), AWS documentation def signing_key generated String_to_sign) # Step 2 (encoded_policy) # correct date date = extract_encoded_policy_date (encoded_policy) Date = time_adjust (on) # encode algorithm date_key = OpenSSL :: all areas HMAC.digest ( ' SHA256, "Avs4 # {@} Sikret_akses_ke" Detksrftime ( "% d of"% of%)) Det_rijn_ke = Openssl :: Hmaskdaijest ( 'SHA256, Det_ke, @rijn) Det_rijn_srvis_ke = Openssl :: Hamas .digest ('SHA256', date_region_key, @service) sign_key = OpenS SL :: HMAC.digest signing_key end def time_adjust (on) time = Time.parse (date) time ( 'SHA256', date_region_service_key, 'aws4_request') + = Time.utc_offset time.utc end
After a little searching in the net, I have encountered it. Apply this code and upload successful iv'e
Signature = OpenSSL :: HMAC.digest (OpenSSL :: Digest :: Digest.new ( 'SHA1'), @secret_access_key, string_to_sign) Base64.encode64 (signed) .gsub ( "\ N "," ")` `
This is short for the client-side code.
Here is some literature I found useful:
What is the difference between the two?
How can I get the first option to work and upload my file? Is the example in AWS page no longer valid?
After doing a research and by comparison I found out that there is a form of AWS that made me There were some redundant areas in using SHA1.
After removing the AWSAccessKeyId area from the form and rename a few other areas, I managed to do AWS4 work.
It has been updated
& lt; Form id = "myForm" action = "http://yourbucket.s3.amazonaws.com/" method = "post" enctype = "multipart / form-data" & gt; & Lt; Input type = "hidden" id = "key" name = "key" value = "upload / $ {filename}" /> & Lt; Input type = "hidden" id = "acl" name = "acl" value = "YOUR_ACL_OPTION" /> & Lt; Input type = "hidden" name = "success_action_redirect" value = "http://google.com" /> & Lt; Input type = "hidden" id = "type" name = "content-type" value = "MIME_TYPE" /> & Lt; Input type = "hidden" name = "x-amz-meta-uuid" value = "14365123651274" /> & Lt; Input type = "hidden" name = "X-maze-credential" value = "YOUR_CREDENTIALS" /> & Lt; Input type = "hidden" name = "X-maze-algorithm" value = "AWS4-HMAC-SHA 256" /> & Lt; Input type = "hidden" id = "date" name = "x-mz-date" value = "" /> & Lt; Input type = "hidden" name = "x-amz-meta-tag" value = "" /> & Lt; Input type = "hidden" id = "policy" name = "policy" value = "YOUR_POLICY_DOCUMENT_BASE64_ENCODED" /> & Lt; Input type = "hidden" id = "signature" name = "x-amaz-sign" value = "YOUR_CALCULATED_SIGNATURE" /> & Lt; Input name = "file" id = "file" type = "file" /> & Lt; Input id = "btn_submit" class = "btn btn-warning" type = "submit" value = "upload file s3" & gt; & Lt; / Form & gt;
No comments:
Post a Comment