POST请求上传到亚马逊失败 [英] POST upload request to Amazon fails

查看:580
本文介绍了POST请求上传到亚马逊失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的图像上传到Amazon S3这个红宝石code:

 要求净/ HTTP /后/多部分

    URL = URI.parse('http://public.domain.com/)
    File.open方法(/ tmp目录/ uup_1114.jpg)做| JPG |
      REQ =网:: HTTP ::邮政:: Multipart.new url.path,
                      '键'=> s3_key,
                      ACL=> s3_acl,
                      CONTENT_TYPE'=> s3_content_type,
                      AWSAccessKeyId'=> s3_AWSAccessKeyId,
                      政策=> s3_policy,
                      签名=> s3_signature,
                      文件=> UploadIO.new(JPG,图像/ PNG,image.jpg文件)
      RES =净:: HTTP.start(url.host,url.port)办| HTTP |
        http.request(REQ)
      结束
    结束
 

和我从亚马逊获得错误:

  

InvalidArgument:斗POST必须包含一个名为键字段。如果它被指定,请检查字段的顺序。

看起来像'文件'场在前的查询,并导致上述错误。我想不出如何发布文件字段在查询结束。

解决方案

我已经成功地使用了AWS-SDK的红宝石创建后的形式

。但是,在我的情况下,我是让用户通过浏览器上传到AWS账户。不过,这可能帮助:

在AWS-SDK提供了一个呼叫一桶名为presigned_post(选件),创建一个pre签订后工作正常。

另请参阅 https://forums.aws.amazon.com/thread.jspa?邮件ID = 296867&放大器;#296867

I'm trying to upload image to Amazon S3 with this Ruby code:

    require 'net/http/post/multipart'

    url = URI.parse('http://public.domain.com/')
    File.open("/tmp/uup_1114.jpg") do |jpg|
      req = Net::HTTP::Post::Multipart.new url.path,
                      'key' => s3_key,
                      'acl' => s3_acl,
                      'content_type' => s3_content_type,
                      'AWSAccessKeyId' => s3_AWSAccessKeyId,
                      'policy' => s3_policy,
                      'signature' => s3_signature,
                      "file" => UploadIO.new(jpg, "image/png", "image.jpg")
      res = Net::HTTP.start(url.host, url.port) do |http|
        http.request(req)
      end
    end

And I'm getting error from Amazon:

InvalidArgument: Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.

Looks like 'file' field goes first in query and that causes an error above. I can't figure out how to post file field at the end of query.

解决方案

I have successfully used the AWS-SDK in ruby to create post forms. But in my case I was getting users to upload from a browser into an AWS account. Still this may help:

the aws-sdk has a call on a bucket called presigned_post(options) that creates a pre signed post that works fine.

See also https://forums.aws.amazon.com/thread.jspa?messageID=296867&#296867

这篇关于POST请求上传到亚马逊失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆