基于浏览器的上传使用POST

编程入门 行业动态 更新时间:2024-10-28 13:21:22
本文介绍了基于浏览器的上传使用POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图创建一个使用POST与AWS签名版本4的客户端上传。 按文件

I'm trying to create a client side uploads using POST with Signature Version 4 of AWS. According to the documents

当我生成的签名在服务器端,我得到在的这个例子页面。

When i'm generating the signature on the server side I get an exact match with AWS signature mentioned in this example page.

然而,当我用它来上传页面我得到这个错误:

However when I use it to upload the page I get this error:

我们计算并不您提供的签名相匹配SignatureDoesNotMatchThe请求签名。检查你的密钥和签名方法

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method

这是在code我用:

OpenSSL::HMAC.hexdigest('sha256', signing_key(string_to_sign), string_to_sign) # step 2 in the aws documentation def signing_key(encoded_policy) # generate the correct date date = extract_encoded_policy_date(encoded_policy) date = time_adjust(date) # encode all the fields by the algorithm date_key = OpenSSL::HMAC.digest('sha256',"AWS4#{@secret_access_key}", date.strftime("%Y%m%d")) date_region_key = OpenSSL::HMAC.digest('sha256',date_key, @region) date_region_service_key = OpenSSL::HMAC.digest('sha256',date_region_key, @service) signing_key = OpenSSL::HMAC.digest('sha256',date_region_service_key, 'aws4_request') signing_key end def time_adjust(date) time = Time.parse(date) time += time.utc_offset time.utc end

在净一点点的搜索,我以前遇到过这种文章。 Iv'e实现了这个code和上载成功。

After a little search in the net, i've encountered this article. Iv'e implemented this code and the upload succeeded.

signature = OpenSSL::HMAC.digest( OpenSSL::Digest::Digest.new('sha1'), @secret_access_key, string_to_sign) Base64.encode64(signature).gsub("\n","")```

这是一个小的演示为客户端code。

This is a small Demo for the client side code.

下面是一些文献,我发现有用: 一般说明 从AWS一些code段

here is some literature I've found useful: General description Some code snippets from AWS

什么是两者之间的区别是什么? 我怎样才能得到工作,并上传我的文件的第一个选项? 在AWS页的例子不再有效?

What is the differences between the two? How can I get the first option to work and upload my files? Is the example in the AWS page no longer valid?

推荐答案

研究和比较的 AWS张贴例如我发现有在做AWS认为我使用SHA1形式的一些冗余字段。

After a research and comparing the AWS post example i found out that there were some redundant fields in the form that made AWS think i'm using SHA1.

在从形式去除AWSAccessKeyId领域和重命名其他一些领域我设法使AWS4工作。

After removing the AWSAccessKeyId field from the form and renaming some other fields I managed to make the AWS4 work.

这是更新的演示

<form id="myForm" action="yourbucket.s3.amazonaws/" method="post" enctype="multipart/form-data"> <input type="hidden" id="key" name="key" value="uploads/${filename}"/> <input type="hidden" id="acl" name="acl" value="YOUR_ACL_OPTION"/> <input type="hidden" name="success_action_redirect" value="google" /> <input type="hidden" id="type" name="Content-Type" value="MIME_TYPE"/> <input type="hidden" name="x-amz-meta-uuid" value="14365123651274" /> <input type="hidden" name="X-Amz-Credential" value="YOUR_CREDENTIALS" /> <input type="hidden" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" /> <input type="hidden" id="date" name="X-Amz-Date" value="" /> <input type="hidden" name="x-amz-meta-tag" value="" /> <input type="hidden" id="policy" name="Policy" value="YOUR_POLICY_DOCUMENT_BASE64_ENCODED"/> <input type="hidden" id="signature" name="X-Amz-Signature" value="YOUR_CALCULATED_SIGNATURE"/> <input name="file" id="file" type="file"/> <input id="btn_submit" class="btn btn-warning" type="submit" value="Upload File to S3"> </form>

更多推荐

基于浏览器的上传使用POST

本文发布于:2023-06-06 04:39:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/534704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器   上传   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!