s3_direct_upload icon indicating copy to clipboard operation
s3_direct_upload copied to clipboard

Policy Condition failed: ["starts-with", "$Content-Type", ""] error

Open mmc1ntyre opened this issue 12 years ago • 16 comments

Any ideas why this would be happening?

AccessDenied Invalid according to Policy: Policy Condition failed: ["starts-with", "$Content-Type", ""] D7C6C1FE8775221F 5qRPVAAM/6iZF0w8vfOlrm67FXoCiDZyDeZklt/lL2ndLb4+/Cry4JclqN/Zsw7L

mmc1ntyre avatar Dec 20 '12 17:12 mmc1ntyre

It's most likely a configuration bug. Double check your CORS policy on the S3 server. The declared server must match the one you are using.

pomartel avatar Dec 20 '12 20:12 pomartel

I went through the Railscasts tutorial again and added a coffee script file "similar" to the one at ....

https://github.com/railscasts/383-uploading-to-amazon-s3/blob/master/gallery-jquery-fileupload/app/assets/javascripts/paintings.js.coffee

Once I did this it worked. I'm not sure if gem was supposed to have this baked in or the documentation needs updating.

mmc1ntyre avatar Dec 20 '12 21:12 mmc1ntyre

The Content-Type hidden field isn't being included in your form most likely. Did you use the form helper this gem provides or the one in the railscast?

waynehoover avatar Dec 21 '12 15:12 waynehoover

Thanks for everyone's help...the issue is fixed

mmc1ntyre avatar Dec 22 '12 00:12 mmc1ntyre

I'm having this problem. How do I get this fix?

peleteiro avatar Jan 17 '13 16:01 peleteiro

your getting this error? Invalid according to Policy: Policy Condition failed: ["starts-with", "$Content-Type", ""]

waynehoover avatar Jan 17 '13 17:01 waynehoover

Yes

peleteiro avatar Jan 23 '13 13:01 peleteiro

Putting this into form resolves the error:

hidden_field_tag  "Content-type", ""

I have not found yet the reason why my S3 bucket expects this field. Apparently this demo works without this field: https://github.com/pjambet/direct-upload

squareduck avatar Feb 19 '13 08:02 squareduck

i am also seeing this

ahoward avatar Feb 27 '13 14:02 ahoward

I am also having this problem. The funky thing is that it was working fine.

bhserna avatar Apr 21 '13 20:04 bhserna

Make sure you use the correct helper method in your view, something like:

<%= s3_uploader_form callback_url: model_url, callback_param: "model[image_url]", id: "myS3Uploader" do %>
  <%= file_field_tag :file, multiple: true %>
<% end %>

Are you doing this?

waynehoover avatar Apr 21 '13 20:04 waynehoover

Yes but without the callbacks

<%= s3_uploader_form id: "myS3Uploader" do %>
  <%= file_field_tag :file, multiple: true %>
<% end %>

bhserna avatar Apr 21 '13 20:04 bhserna

When you look at the HTML this helper method generates the form tag should look like this:

<form accept-charset="UTF-8" action="https://s3.amazonaws.com/bucket-name" data-callback-method="POST" data-callback-param="file" data-callback-url="null" enctype="multipart/form-data" id="s3uploaderz" method="post">

...

</form>

Does yours? It seems that for some reason some browsers are not sending the content-type header when posting the form, I'm trying to track down why. In the mean time you can just add the hidden field like @danvelduck did like so:

<%= s3_uploader_form id: "myS3Uploader" do %>
  <%= hidden_field_tag  "Content-Type", "" %>
  <%= file_field_tag :file, multiple: true %>
<% end %>

waynehoover avatar Apr 21 '13 20:04 waynehoover

sorry, it was my problem ... in my assets I had a a different version of the "jquery.fileupload.js" ... I just remove that and now is working.

I think the problem was that this line https://github.com/waynehoover/s3_direct_upload/blob/master/app/assets/javascripts/s3_direct_upload.js.coffee#L90

was not doing its job.

Thanks, for your help

bhserna avatar Apr 21 '13 20:04 bhserna

I'm having the same issue. I followed the readme to set up. One difference is that I am loading my form via an ajax request, so I'm doing my $("#s3-uploader").S3Uploader(); in the new.js.erb for my image model instead of doing it in my application script (which seems to be working ok). I've added the hidden input field as suggested and also revised my CORS to match the example in the readme. Any ideas what else I could try or what kind of information would help find the issue?

Thanks for your help

webbtj avatar Aug 22 '13 16:08 webbtj

I had the same issue, I was able to fix it by adding () to the S3Uploader function call jQuery("#fileS3Uploader").S3Uploader() instead of jQuery("#fileS3Uploader").S3Uploader

david-a avatar Apr 22 '14 13:04 david-a