2016-06-28 13 views
0

ich folgende Fehlermeldung erhalten, wenn ich versuche, ein Bild zu S3 laden:Fehler 400, wenn bis S3 Hochladen eines Bildes

POST https://bucket-name.s3.amazonaws.com/ 400 (Bad Request) 

In meinem Controller, ich bin vorbei:

@s3_direct_post = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read') 

In meiner Meinung nach, ich habe:

<%= form_for(@student, html: { class: 'directUpload', data: { 'form-data' => (@s3_direct_post.fields), 'url' => @s3_direct_post.url, 'host' => URI.parse(@s3_direct_post.url).host } }) do |f| %> 

initializers/aws.rb:

Aws.config.update({ 
    region: 'us-east-1', 
    credentials: Aws::Credentials.new('ABC', 'XYZ'), 
}) 

S3_BUCKET = Aws::S3::Resource.new.bucket('bucket-name') 

I addierten die folgenden CORS Konfiguration meiner Eimer:

<?xml version="1.0" encoding="UTF-8"?> 
    <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
<CORSRule> 
    <AllowedOrigin>http://localhost:3000</AllowedOrigin> 
    <AllowedMethod>GET</AllowedMethod> 
    <AllowedMethod>POST</AllowedMethod> 
    <AllowedMethod>PUT</AllowedMethod> 
    <AllowedHeader>*</AllowedHeader> 
</CORSRule> 

ich das Tutorial hier folgt: https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails. Gibt es einen Unterschied zwischen einem "Produktions-Bucket" und einem "Entwicklungs-Bucket"?

Antwort

0

Das Problem war mit der Region. Interessant, weil ich dachte, dass S3-Buckets global sind.

+0

Sie möchten vielleicht [Arbeiten mit Amazon S3-Buckets] (http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html) überprüfen. –

Verwandte Themen