javascript - 上传到亚马逊 S3

标签 javascript ruby-on-rails amazon-s3

我正在尝试将图片上传到 amazon S3。我成功地使用了载波。然后我切换到 jQuery 多图像上传。关注 railscast 383。

我的 upload_helper 看起来和显示的一模一样;除了初始化方法。 https://github.com/railscasts/383-uploading-to-amazon-s3/blob/master/gallery-jquery-fileupload/app/helpers/upload_helper.rb

以下是用户可以上传照片的页面:

    = s3_uploader_form post: items_url, as: "painting[image_url]" do
        = file_field_tag :file, multiple: true

    %script#template-upload{type: "text/x-tmpl"}
        .upload
            {%=o.name%}
            .progress
                .bar{ style: "width: 0%" }

我也有以下js:

//= require jquery-fileupload/basic
//= require jquery-fileupload/vendor/tmpl
//= require paintings

如教程中所示

即使我的 S3 上传在载波和单个文件上传方面工作正常,我还是得到了

failed to upload image error (coming from the last line in paintings.js.coffee). and 
Failed to load resource: the server responded with a status of 400 (Bad Request)

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>XYZ</RequestId>
    <HostId>
        XYZ
    </HostId>
</Error>

我的 CORS 配置是:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>http://localhost:3000</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

非常感谢任何指导

最佳答案

找到了!!!

在 upload_helper > S3Uploader > initialze 中为你的'expiration:'添加一个时区,像这样:

    expiration: 10.hours.from_now.utc,

这对我来说很神奇

祝你好运

关于javascript - 上传到亚马逊 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14410938/

相关文章:

javascript - 不使用 setState 修改 state 有什么风险?

ruby-on-rails - 如何使用 Tire 在 Elasticsearch 中索引附件?

ruby-on-rails - Rspec 中的 Stub Devise 'current_user' 方法,无需加载 Rails

hadoop - 如何在 Hadoop 中创建从 1..N 开始的迭代器?

asynchronous - Amazon S3 异步分段上传

amazon-web-services - 使用 Python 向 AWS S3 发出批量复制请求

javascript - Jquery 克隆只重复一次。需要重复多次

javascript - 在 angular js div 中使用应用程序名称不起作用

ruby-on-rails - 扩展 Ruby on Rails 站点

javascript - TinyMCE 将内容从弹出对话框传递到编辑器